Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different image reload in the page when i click in the refresh(f5)

 
s paul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Different image reload in the page when i click in the refresh(f5) and also images will come in sequence... like img1 ,img2, img3... but not randomly...

Please give me the solution. it very Essential for me.

thank you.

Soumen
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you would need to store a cookie value with what index the person is on. When the page loads you read the cookie and you set the source of the image with a value from an array.

Eric
 
s paul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code. please have a look.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change Images</title>
</head>

<body>
<script language="JavaScript">
<!--
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
//alert("VAL: " + ad);
if (ad==1) {
alt="PRIME definition"; banner="images/image1.jpg";
width="750";
height="500";
}
if (ad==2) {
alt="PRIME definition"; banner="images/image2.jpg";
width="750";
height="500";
}
if (ad==3) {
alt="PRIME definition"; banner="images/image3.jpg";
width="750"; height="500";
}
document.write('<center>');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0><br>');
document.write('</center>');
// -->
</script>
</body>
</html>


images should be come in sequence...like img1 ,img2, img3....... img1, img2. img3... for every refresh ... but not randomly... and work in all browser...

Please help me.

thanking you

soumen
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you post code here, please use code tags.

As I said before, you need to use a cookie to store the last value. When your code first loads you check the cookie and see if there is a value, if there is use it.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic