Log in

View Full Version : Refresh webpage automatically without clicking refresh button



fung
03-26-2007, 08:49 AM
Hi,

Anybody knows how to make the page refresh automatically without clicking the refresh button on IE?

Please advice.

Thanks.

djr33
03-26-2007, 09:10 AM
This can only be done with javascript if it must be done by a command (as in with some sort of link, button, movement, etc.)
You can use something like this:
<img onClick="window.location('next.htm');">
That's an example with an image, but it would work with other things as well.
You would use the same name as the current page to refresh, rather than go to a new page.
Maybe (not sure on this) window.location(window.location) would work to do that automatically.


The other way to do this is with a meta refresh tag.

This goes near the top of your head section.

<meta http-equiv="refresh" content="3;url=http://my.com/page.htm">

the green numerical value is the number of seconds before refeshing. This WILL refresh after 3 seconds, no matter what, with no control over this due to user interaction, etc.
Change to 0 for immediate or any higher value for a longer pause.

The red value is the url to which it is sent... this can be a redirect or reload.
To make it just reload, just remove the second part, so you only have:
content="3", without the ;url=... part.

Remember that this will just affect the current page, so if you create a loop to the same page, the refreshing will continue forever, each X seconds. But if you link to another page, it will just stop after going there, unless, of course, that page also has a refresh on it.

Twey
03-26-2007, 01:09 PM
location.reload() is fine for JS.

djr33
03-26-2007, 01:10 PM
Ah, good. That's easy.