View Full Version : Refresh at Time

Sep 19th, 2007, 04:21 AM
I would like to have a webpage automatically refresh at specific times, but I'm not sure how to code it.
Ex. It refreshes at 10:20AM and 11:10AM.

Philip M
Sep 19th, 2007, 08:48 AM
Try this:-

<script type = "text/javascript">

function refresh() {
var now = new Date();
var hh = now.getHours();
var mn = now.getMinutes();
var flag = 0;
if (hh == 10 && mn == 20) {flag = 1}
if (hh == 11 && mn == 10) {flag = 1}
// add more times to refresh as required
if (flag == 1) {
window.location = window.location;
flag = 0;
window.setTimeout("refresh()", 60000) // at 1 minute intervals


If you want to refresh at exactly 10.20.00 you will need to add another variable ss = now.getSeconds() and change the setTimeout value to 1000 (every second).

Sep 19th, 2007, 03:17 PM
If you want to add the seconds instead of running the function on each second you can instead calculate how many seconds to make the time 00 should be added and then add it to the timer.
Like if you have 24 seconds on the timer you can just add 36 seconds to the delay and then just run the script again every minute.

Philip M
Sep 19th, 2007, 03:50 PM
Accuracy to the second is fairly pointless as the time is defined by the clock setting in the user's computer, which of course may be wildly inaccurate. If the correct time is really important you will need to adopt a server-side solution.