Actually, I had another look at the script I'm using (to present a random quote, not a picture, but the principle's the same). It's slightly different...
Put the following in a file on its own. Call it, say, "showpic.js":
[tt]
var theImages = new Array()
Images[0] = '1.gif'
Images[1] = '2.gif'
Images[2] = '3.gif'
Images[3] = '4.gif'
//add more images here ...
var Pick = Math.round(Math.random()*(Images.length-1));
document.write('<img src="'+Images[Pick]+'" />');
[/tt]
Now, on the web page where you want the image to appear, put this instead:
[tt]
<script language="JavaScript" src="showpic.js" type="text/javascript"></script>
[/tt]
I'm not a JavaScript expert, and haven't tested this, but it should do the trick for most people. You can see my random quote version in action at
and
.
The advantages of using JS to do the randomising at the browser end are that it's (relatively) simple, possible on freebie hosts as well as paid ones, and the random images won't be cached - ensuring that you get a fresh roll of the dice each time you load the page.
The disadvantage is that people who surf with JS switched off (for whatever reason) will not see your images - the script will be ignored. If you want to be sure your images show up, you'll need to use some kind of server-side scripting. Here's a link to some perl scripts, there's also some remotely hosted services there if you don't have your own cgi-bin...
My McGonagall site uses Javascript for the (eye-candy) quote at the top of each page, but server-side script for the (vital) "Gem of the Day" on certain pages.
-- Chris Hunt
Extra Connections Ltd
The real world's OK for a visit, but you wouldn't want to LIVE there!