Solved

Refresh automatically?

Posted on 2000-05-09
5
244 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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