<HTML>
<head>
<Title> Page Title Here</Title>
<SCRIPT language="JavaScript">
<!-- Begin JS Script -->
<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.
theImages[0] = 'http://www.dl.utoledo.edu/images/header1.jpg'
theImages[1] = 'http://www.dl.utoledo.edu/images/header2.jpg'
theImages[2] = 'http://www.dl.utoledo.edu/images/header3.jpg'
theImages[3] = 'http://www.dl.utoledo.edu/images/header4.jpg'
theImages[4] = 'http://www.dl.utoledo.edu/images/header5.jpg'
theImages[5] = 'http://www.dl.utoledo.edu/images/header14.jpg'
theImages[6] = 'http://www.dl.utoledo.edu/images/header15.jpg'
// do not edit anything below this line
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
// End -->
</script>
</head>
<!--In the body where you want the random images to appear-->
<body>
<SCRIPT language="JavaScript">
<!-- Begin
showImage();
// End -->
</script>
</body>
</HTML>
Comments
Excellent Instructions
You provided an excellent description of how to use and place this code! Thanks for your thoroughness. It will be extremely easy to implement.
Sue
Learning Technology Trainer
Why use so much code?
I find this code (below) works in my browser just as well. Is there some reason you have put the loop in there that I'm not familiar with?
// do not edit anything below this line
var p = theImages.length;
var i = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[i]+'">');
}
What' wrong with this picture?
That code as it is, does work, THANK YOU!
I can make it loop through a folder using ASP or PHP.
Very simple really, did one here yesterday for that KW image thingy. http://www.jtechsystems.co.za/views.php?newsid=16/
The same rules apply here.
Enjoy...
You must me logged in to write a comment.