The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript random img on page load Re: random img on page load

Chris Coyier

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: … -an-image/