Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Refresh automatically?

Posted on 2000-05-09
5
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 150 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

604 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