Image change with refresh or load a page by javascript

<SCRIPT LANGUAGE="JavaScript">
var theImages = new Array()

      theImages[0] = 'iphone-FASTEST.jpg'
      theImages[1] = 'apple-3gs-0.jpg'
      theImages[2] = 'apple-iphone-3gs-2-0.JPG'
      theImages[3] = 'iphone-accessibility.jpg'
      theImages[4] = 'iphone-cutcopypaste.jpg'
	  
	  
	  

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(){
if(whichImage==0){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==1){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==2){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==3){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==4){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}


}

</script>


The call this where u want to show the image

 <div>
	  Image here
	  
	  <script>showImage();</script>

	  </div>

Advertisements

Tagged: ,

7 thoughts on “Image change with refresh or load a page by javascript

  1. midpart April 7, 2010 at 9:49 am Reply

    KI korbo boss ja pai tai to note book e likhe rakhi. ar eta to amar note book. Ar sobai to tor moto boss public na.:P

  2. Sayed Rahman (Shagor) May 13, 2011 at 12:23 pm Reply

    Hi,
    Thanks, its realy great……………………….
    Everything is important which is needed to others.

    sayed

  3. humrahimcs June 5, 2011 at 2:28 am Reply

    This is Great Article which is great help me to customize according to my requirement from database to load image and change at page refresh

    If you want to Change Image at load a page or Refresh
    Then Visit This MY blog Link

    http://humrahimcs.wordpress.com/2011/05/25/dynamic-change-image-from-database-after-page-refresh/

  4. stu figler January 20, 2012 at 2:02 pm Reply

    I’ve tried this script and it worked great. Originally, I was planning on having 30 or 40 different images so the idea of random loading made sense. However, I’ve decided to only do 10 images so I was wondering if there’s a way to modify the script so that the images load either sequently or “sort of randomly.” (What I mean by that last one is so that pictures load randomly but, perhaps, it HAS to be a different picture than the one or two or three before.)

    Anyway, I’m not much of a code monkey, just finding my way, but this script is really great and I appreciate your sharing it.

    stu

  5. Local Thailand April 30, 2013 at 3:43 pm Reply

    Thank you for great script

  6. cianidebs May 14, 2013 at 4:19 pm Reply

    i put this script two times in the same html document, because i want many different space where image changing. but, right now, i can see only one images group. in two different places. how can i do?

  7. Noman Sayyed February 3, 2015 at 9:13 pm Reply

    Thanks for sharing this article is so helpful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: