Link to home
Start Free TrialLog in
Avatar of tdewald
tdewald

asked on

Auto-Refresh at Specific Intervals

<meta http-equiv="refresh" content="3600">

Okay, what I'm trying to do is make a website auto-refresh every 60 minutes.  The code above was originally for 10 seconds, and worked great.  However, it doesn't work for 3600 seconds (1 hour).  What code do I need to type to make it refresh once per hour?

Alternately, is there a way I can sync it to the computer's clock to just update at 5 minutes after the top of the hour?

Thanks.
Avatar of seanpowell
seanpowell
Flag of Canada image

This will do a refresh once an hour:

<script language="JavaScript">
<!--
if (document.images)
    setTimeout('location.reload(true)',1000*3600); // forces a reload from the server
else
    setTimeout('location.href = location.href',1000*3600);  // just reloads the page
//-->
</script>
ASKER CERTIFIED SOLUTION
Avatar of Zontar
Zontar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
better of placing both since some browsers disable meta refresh:

<meta http-equiv="refresh" content="3600;URL=thesamepage.html">
<script type="text/javascript">
theHour="1"; //Input the hour
setTimeout("location.reload()",theHour*1000*60*60)
</script>

and for the 5 minutes:

<meta http-equiv="refresh" content="300;URL=thesamepage.html">
<script type="text/javascript">
theMinutes="5"; //Input the minutes
setTimeout("location.reload()",theMinutes*1000*60)
</script>

gam3r
Avatar of crazycomputers
crazycomputers

Zontar, your answer is almost right, except for the delay in setTimeout.  You are making it check every hour to see if it's five minutes after the hour.  Not only would this be the same as the meta refresh, but it will likely never refresh considering that the chances of a user loading the page at five minutes past any hour is slim.  Remove one of the 60s and it'll work - check every minute instead of every hour.