Solved

Refresh automatically?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embedding Tags in a restricted UI 6 31
HowTo set a global variable in javascript or jQuery 4 41
Search Item in Table 2 43
output in HTML in Powershell 5 23
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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 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