Solved

Refresh automatically?

Posted on 2000-05-09
5
240 Views
Last Modified: 2010-04-09
Hi,
I saw some homepages(forgot the URLs already) which contain some images which can refresh themselves automatically.  The most special is that only the images are changed(random image), but the whole page hadn't got reloaded.  Therefore, the visitor will not be disturbed by the refresh action of the images.

How can I achieve this?  Will "layer" help?
Thanks in advance.
PS.  Please don't suggest me to use frames.
0
Comment
Question by:nyt
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 2791806
They use javascript:

<html>
<head>
<script>
myImageNames = new Array('image0','image1','image2','image3')
myImages = new Array();

/* preload */

if (document.images) {
   for (i=0;i<myImages.length;i++) {
      myImages[i] = new Image();
      myImages[i].src = myImageNames[i] +'.jpg';
   }
}

count = 0
function swap() {
   if (!document.images) return;
   count++;
   if (count > myImages.length) count = 0;
   document.images['banner'].src = myImages[count].src;
   setTimeout('swap()',5000);
}
</script>
</head>
<body onLoad="swap()">
<img src=image0.jpg name=banner>

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2791811
If you want just one new image each time the page is loaded you need to use cookies.

Michel
0
 

Author Comment

by:nyt
ID: 2791864
I use Netscape.
The code seems not working under Netscape.  Netscape gave me this error message:
"Line 21: myImages[count] has no properties."

How can I correct this so that the code can work under both Netscape and IE?
0
 

Author Comment

by:nyt
ID: 2791887
Moreover,
I prefer not using "Preload"...since the image files are actually changing with time.  That is something like a counter, the code loads the image file in regular intervals, so that the counter image can give the most updated info.

Of course, I am not do this for a counter.  Counter is used to explain what I want.

Thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2791906
Bug. I just whipped it up from the top of my head...

change

if (count > myImages.length) count = 0;

to

if (count >= myImages.length) count = 0;


To not preload use this:

<html>
<head>
<script>
myImages = new Array('image0.jpg','image1.jpg','image2.jpg','image3.jpg')
count = 0
function swap() {
   if (!document.images) return;
   count++;
   if (count >= myImages.length) count = 0;
   document.images['banner'].src = myImages[count];
   setTimeout('swap()',5000);
}
</script>
</head>
<body onLoad="swap()">
<img src=image0.jpg name=banner>

Michel
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now