tags:

views:

452

answers:

4

I have a website that I want to be reloaded at a certain time, like 3:35pm, not after a specific interval like 5min. How do I do that?

+4  A: 

The following JavaScript snippet will allow you to refresh at a given time:

function refreshAt(hours, minutes, seconds) {
    var now = new Date();
    var then = new Date();

    if(now.getHours() > hours ||
       (now.getHours() == hours && now.getMinutes() > minutes) ||
        now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
        then.setDate(now.getDate() + 1);
    }
    then.setHours(hours);
    then.setMinutes(minutes);
    then.setSeconds(seconds);

    var timeout = (then.getTime() - now.getTime());
    setTimeout(function() { window.location.reload(true); }, timeout);
}

Then you can add a script tag to call the refreshAt() function.

refreshAt(15,35,0); //Will refresh the page at 3:35pm
Andrew Moore
A: 

Basically, when the page is accessed, calculate how much time is remaining between the access time and the time you want to reload the page, and use that remaining time in the meta refresh header. Obviously this would need to be done in a CGI script or web application, or possibly with SSI (server-side includes); it won't work if all you have is a static HTML file.

Another alternative would be to use Javascript, but it won't work if the client has Javascript disabled.

David Zaslavsky
**@David:** The problem with doing it server-side is that timezones differ, and you don't always have the information on the client's tz.
Andrew Moore
That may not be necessary. The OP didn't say whether he wanted to reload the page at a given time in the client's timezone or the server's timezone.
David Zaslavsky
+1  A: 
<META HTTP-EQUIV="Refresh" CONTENT="5">

this will force page to reload every 5 seconds. Just calculate the correct interval and add it to content tag

Sorantis
**@Sorantis:** The problem with doing it server-side is that timezones differ, and you don't always have the information on the client's tz.
Andrew Moore
You are right. I guess Javascript is the optimal solution.
Sorantis
Question is about specific time and not intervals of time
random
A: 

Basically, there are many javascript codes out there that can refresh the page ever so minutes or something, you can edit them to refresh at hours too. Like this one:

//enter refresh time in "minutes:seconds" Minutes: 0 to Whatever
//Seconds should range from 0 to 59
var limit = "0:30";

if (document.images) {
    var parselimit = limit.split(":");
    parselimit = parselimit[0] * 60 + parselimit[1] * 1;
}
var beginrefresh = function () {
    if (!document.images) return if (parselimit == 1) window.location.reload()
    else {
        parselimit -= 1;
        curmin = Math.floor(parselimit / 60);
        cursec = parselimit % 60;
        if (curmin != 0) curtime = curmin + " minutes and " + cursec + " seconds left until page refresh!";
        else curtime = cursec + " seconds left until page refresh!";
        window.status = curtime;
        setTimeout("beginrefresh()", 1000);
    }
}

window.onload = beginrefresh;

(now just calculate the minutes and seconds you want it to refresh, like for example noon everyday if it were noon now:

var limit = "1440:00";

Now you could use this code except, most of them don't work with server time, And with the information you provided us, we really can't do anything more. Edit your question and tell us if you want it to be timed with the servers time, or something else.

Tony C