• Javascript random image
    7 replies, posted
Right now I'm using a code like this in my css to get a random background: [code]background-image:url(pf_header<?php echo rand(1,13); ?>.jpg);[/code] In this way, I'm obliged to have the css included in the php page, but I want to move it out, so I'd need to change it to javascript. I'd have to like put a "placeholder" background at first, and when the page is loaded change it randomly with javascript just like I did with php. If you answer, please keep in mind I know nothing about javascript so please also explain the solution.
You [i]could[/i] use Javascript, but it'll fuck up for users who don't have JS. Maybe stick that in an external file like background.css.php, and link to it from the HTML file.
[QUOTE=turb_;22786379]You [i]could[/i] use Javascript, but it'll fuck up for users who don't have JS. Maybe stick that in an external file like background.css.php, and link to it from the HTML file.[/QUOTE] Just have the background as a PHP file, and set the content-type to the correct one.
I would use JS, and if the user does not use JS, just have it use a default background cuz those people do not worry much about how a website works lol.
[QUOTE=bios_hazard;22790427]I would use JS, and if the user does not use JS, just have it use a default background cuz those people do not worry much about how a website works lol.[/QUOTE] Pretty much this, default image, than change with JS
[quote]In this way, I'm obliged to have the css included in the php page, but I want to move it out, so I'd need to change it to javascript.[/quote] Not really, you could do <body styles="background-image: php_code;">blah</body>
[QUOTE=Fizzadar;22786907]Just have the background as a PHP file, and set the content-type to the correct one.[/QUOTE] How do you do that?
[QUOTE=Reg;22823594]How do you do that?[/QUOTE] Set Content Type [code] header("Content-type: " . mime_content_type($fileLocation)); [/code] Read File [code] readfile($fileLocation); [/code]
Sorry, you need to Log In to post a reply to this thread.