You'd have to use a cookie-based solution IMHO... otherwise every time the page refreshed, it would refresh itself again (because it had just refreshed, and the refresh code would kick in, etc etc ad infinitum).
Dan
The answers you get are only as good as the information you give!
If you have any graphics on the page, and someone connects with a slow dialup connection, they'll never get to see the whole page load. As well, if you reload the page every 5 seconds, what's going to happen when someone tries to scroll down and see what's at the bottom of the page? Will they ever be able to do that? Sounds like a recipe to keep people away from your website. If you have one item that you want to refresh, why not put it in an iframe and just refresh that as you wish (though if it takes more than 5 seconds to reload, the viewer will never be able to see the information there)?
If you just want to refresh a certain part of your web page, the best way to do it would probably be to either use an IFrame like Lee suggest or use the XMLHTTP object to fetch the page behind the scenes and update the content on the page. Much less blinking that way.
That's just an Idea but you can try something like this (I didn't try it so there may still errors):
<HTML>
<SCRIPT language = "javascript">
var timeIsOut = false;
function reloadPage(){
var newLocation = window.location + '?reloaded=true';
if(!reloaded || timeIsOut)
window.location = newLocation;
else
setTimeout('reloadPage()', 5 * 60);
timeIsOut = true;
}
</SCRIPT>
<BODY onLoad = "javascript:reloadPage();">
...
</BODY>
</HTML>
So.. not sure that's correct and not sure that's what you wanted. You do not need to use cookie. Just When you are refreshing the page just indicates that you have already done it with a variable that you gives with the url (reloaded in my example). The timeIsOut variable indicates that the next time the reloadPage function is called (after five minuts because of the setTimeout instruction) it will reload the page even if the reloaded variable is true
I just had a great original idea. If you passed a flag in the querystring after you reload, you could reload the page if the flag isn't there and you wouldn't need to use cookies! Damn I'm smart!
Hello meeble, after doing extensive research and thinking long and hard on this subject, I think that cookies or some querystring manipulation would do the trick.
I've put together a solution in the past that used an extra parameter (like a query string). It required the user to have javascript installed, because onload I would check the location to see if there was a '?' in there... if not... redirect to the same page with a parameter.
Now... unlike the other solutions here... I use the word parameter.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.