I'm new to Java script. Maybe some of you experts can help?
i'm trying to use the following code i found online but I want it to consider all the jpg files in this directory images/rand/ and open one randomly....there are about 1000 fotos and i want them displayed at random every time the user goes to my site:)
Code: Select all
<SCRIPT LANGUAGE="JavaScript">
var theImages = new Array()
//Random images...maybe some loop to consider all jpg files in images/rand/ directory??
theImages[0] = 'images/rand/1.jpg' // replace with names of images
theImages[1] = 'images/rand/2.jpg' // replace with names of images
theImages[2] = 'images/rand/3.jpg' // replace with names of images
theImages[3] = 'images/rand/4.jpg' // replace with names of images
theImages[4] = 'images/rand/5.jpg' // replace with names of images
theImages[5] = 'images/rand/6.jpg' // replace with names of images
theImages[6] = 'images/rand/7.jpg' // replace with names of images
theImages[7] = 'images/rand/8.jpg' // replace with names of images
theImages[8] = 'images/rand/9.jpg' // replace with names of images
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('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
}
</script>i'm using this to show image:
Code: Select all
<script>showImage();</script>