Home › Forums › JavaScript › random img on page load › Re: random img on page load
February 20, 2009 at 12:21 am
#53834
Chris Coyier
Keymaster
One thing I notice is that your original "src" starts with "Raw Images/", while the file paths in your JavaScript are just the image name. And.. when you set the .src in your randomImage function, you use "i", but "i" was declared outside of the function so it won’t know what that is. And.. that line should start "var" not "ar". And.. it should be " = images not Raw Images.
But anyway, I don’t think JavaScript is the right route for this. Why rely on a client side language when that could potentially be disabled?
Here is a really easy and "quick and dirty" way to do it with PHP: