mineemee
12-25-2007, 10:48 PM
I am trying to have my page load images at random whenever someone loads or refreshes the page. I am looking for a very simple script and I'm thinking that this is best done with javascript. A great example of what i'm looking for is the header image at www. nyu.edu everytime you load the page a different image comes up. However this script seems very complex.
can this be altered to get what I want?
I found this easy script somewhere and is not what i'm looking for but maybe maybe it can be altered:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "Images/home/I01.jpg";
images[2] = new Image();
images[2].src = "Images/home/I02.jpg";
images[3] = new Image();
images[3].src = "Images/home/I03.jpg";
images[4] = new Image();
images[4].src = "Images/home/I04.jpg";
images[5] = new Image();
images[5].src = "Images/home/I05.jpg";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
// End -->
</script>
</head>
<body><a href="#" onClick="swapPic();"><img name="randimg" src="Images/home/I01.jpg"
width="800" height="600" border="0" alt=""></a>
</body>
</html>
Thanks for your help!
can this be altered to get what I want?
I found this easy script somewhere and is not what i'm looking for but maybe maybe it can be altered:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "Images/home/I01.jpg";
images[2] = new Image();
images[2].src = "Images/home/I02.jpg";
images[3] = new Image();
images[3].src = "Images/home/I03.jpg";
images[4] = new Image();
images[4].src = "Images/home/I04.jpg";
images[5] = new Image();
images[5].src = "Images/home/I05.jpg";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
// End -->
</script>
</head>
<body><a href="#" onClick="swapPic();"><img name="randimg" src="Images/home/I01.jpg"
width="800" height="600" border="0" alt=""></a>
</body>
</html>
Thanks for your help!
