View Full Version : refresh page on each load
vzwhaley
11-13-2002, 09:40 PM
Hello everyone!
I am new to this message board and to JavaScript in general. I have a page with an image that is updated once on a daily basis. I am trying to figure out a way to have the page refresh each time the visitor loads the page so that the old image will no longer be in the browser's cache, so to speak.
I have tried several methods, including window.location.reload() and some Web cam scripts, but no matter what I do, the page keeps refreshing over and over and over. Is there not a way to pass an argument to tell the page to refresh only one time?
Sorry for being so stupid, but any help would be most appreciated.
Sincerely,
Vincent Whaley
beetle
11-13-2002, 09:59 PM
Yes, with a session cookie...
function doLoad() {
if (document.cookie == '1') return;
document.cookie = '1';
location.reload();
}
<body onLoad="doLoad();">
vzwhaley
11-13-2002, 10:14 PM
thanks a bunch. but the page keeps refreshing after it loads. it doesn't stop refreshing. this is the problem I keep running into. any ideas? thanks.
vzwhaley
11-13-2002, 10:18 PM
i am sharing the body onLoad with preLoad images. would that have anything to do with it?
<body onLoad="doLoad();MM_preloadImages('images/menus/BackToHome02.jpg', 'FrontPage/front.jpg')">
thanks
beetle
11-13-2002, 10:27 PM
That's fine, and if you like, you can even make a common init() funciton..
function init() {
doLoad();
MM_preloadImages('images/menus/BackToHome02.jpg', 'FrontPage/front.jpg')"
}
<body onload="init();">
Or not, the end result is the same.
whammy
11-14-2002, 12:18 AM
This does the same thing, but it might be more clear (?):
function doLoad() {
if (document.cookie != '1'){
document.cookie = '1';
location.reload();
}
}
<body onload="doLoad()">
P.S. Of course, anyone with cookies disabled will get nothing but a constantly refreshing page, and if they have javascript disabled the page will not refresh at all. :)
Don't browsers usually replace the cache if you append a random querystring to the end of the url, beetle, since perhaps it doesn't see it as the same URL that's been saved in the Temporary Internet Files?
If I'm not totally off base here, that should be rather easy to do - instead of using location.reload() (which BTW I have had problems with myself), perhaps just use:
if(window.location.search.indexOf("ran") == -1){
window.location = location + "?ran=" + somerandomnumber
}
Not sure of the syntax though since I didn't test it, just the concept. :)
glenngv
11-14-2002, 02:34 AM
another trick (if you're not using frames)
if (window.name!="MainWindow"){
window.name="MainWindow";
location.reload();
}
window.name property is persistent
beetle
11-14-2002, 03:14 AM
Nice glenn, I like it. Creative thinking for sure :D
whammy
11-14-2002, 03:15 AM
Yeah... not a bad idea at all. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.