• We are available for any Development work:
  • Email us at: programmer_heart@yahoo.com

Random Image : Change image in every Refresh of page

For displaying the random image  from the available  images, we can do this by  writing a little code  by the  help of Javascript .

You have also required to declared the array of images which you are  going to  show  different images in every refresh of the page.Then copy and paste the following code   you can find your solution.

[code]

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var theImages = new Array() // do not change this
theImages[0] = ’01.jpg’
theImages[1] = ’02.jpg’
theImages[2] = ’03.jpg’
theImages[3] = ’04.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]+’" border="0">’);
}
</script>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
showImage();
</script>
</BODY>

[/code]

4 thoughts on “Random Image : Change image in every Refresh of page

Leave a Reply

Your email address will not be published. Required fields are marked *

Press Enter to Search