Log in

View Full Version : Code to auto refresh page every day?



mlegg
11-29-2011, 01:52 AM
I was looking for a code to refresh a web page every day for repeat visitors in case of any changes that were made.

I would like it to work on all systems and browsers. Is this even possible?

This is one thing that I have found.


<META HTTP-EQUIV="refresh" CONTENT="86400">"
The "86400" part of the code instructs the browser to reload the current page every 86,400 seconds, which is once a day

Or would something with javascript be a better option?


<!-- Codes by Quackit.com -->
<html>
<head>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
// -->
</script>
</head>
<body onload="JavaScript:timedRefresh(5000);">
<p>This page will refresh every 5 seconds. This is because we're using the 'onload' event to call our function. We are passing in the value '5000', which equals 5 seconds.</p>
<p>But hey, try not to annoy your users too much with unnecessary page refreshes every few seconds!</p>
</body>
</html>

of course I would want to change 5000


thanks

djr33
11-29-2011, 02:03 AM
That sounds annoying (just being honest). Visitors would not understand and if the page changed randomly while they were sleeping (or worse, trying to read it), that would be confusing.
I understand a relatively-constantly updating page, but if it's static for 24 hours then randomly reloads, that's odd.

Why not use Ajax for a specific portion of the site to reload more often than that? Maybe a news area that reloads every hour. That seems more reasonable.

Both options you posted above are fine. The meta option will be a little more reliable and it's harder to disable.

But there's a bigger issue: that's going to refresh every 24 hours--- any 24 hours. If you want it to refresh for every new day at midnight, you'll need to use Javascript to figure out when that is, and hope everyone is in the same timezone. Or you could use PHP or another serverside language to generate the right number of seconds until the next day for the server (constant for everyone). If you just randomly have it refresh every 24 hours, it might take up to 23 hours 59 minutes for someone to see your updates... there's no way of knowing.

And finally: why would anyone stay on your page for 24 hours in a row? I don't do that with any websites (except my email-- gmail).

mlegg
11-29-2011, 02:43 AM
The guy who's website I've been doing for a while was asking about it. He is pretty sure he want's a page he can use sort of like a news page. I really don't imagine him updating more than once a day, so that's why I said day in my time frame mentioned.

djr33
11-29-2011, 03:10 AM
But again, if he updates it at 3pm and the page is set to refresh at 2pm, then it will be 2pm the next day, 23 hours after the news was updated. Even if the news does not actually update that often, it's probably more useful to update it every hour (10 minutes? 2 hours? whatever you want) than 24 hours since that's impractical. Again, who will actually stay on the page that long? Unless this is just for him to play with (and I understand-- I like playing with my own websites), it doesn't seem very helpful.

For that sort of situation, I'd again recommend some sort of Ajax, and hopefully one that is a little fancy: it could slide the new messages in so there is some sort of visual cue about an update. That would make the transition a lot less weird. You could based this on a "chat" script model, just a very slow, one-sided conversation.

mlegg
11-29-2011, 03:43 AM
That sounds pretty OK. Do you have any scripts here to help me do that?

edit: I just found some in DD, looking at them now.