I am using javascript to refresh my page at 5:25 pm EST. For example if a user come to my page at 5.00pm EST and he stay at 5.40pm EST let suppose.Then I want to refresh my page at 5.25pm EST.
how can I achieve this?
I am using javascript to refresh my page at 5:25 pm EST. For example if a user come to my page at 5.00pm EST and he stay at 5.40pm EST let suppose.Then I want to refresh my page at 5.25pm EST.
how can I achieve this?
Use setInterval
to check time at specific intervals and if desired time is reached, just use location.reload
:
window.setInterval(funciton() {
var now = new Date();
if(now.getTime() == SOMETHING) {
location.reload();
}
}, REFRESH_INTERVAL);
If you want to use time zone calculation, etc. I suggest moment.js.
UPDATE:
There is a nice snippet provided in this answer, which does it more elegantly.
You can compute time to reload and then set timeout function to reload page:
var now = new Date()
var timeOfRefresh = new Date();
timeOfRefresh.setHours(5);
timeOfRefresh.setMinutes(25);
timeOfRefresh.setSeconds(0);
var diff = timeOfRefresh.getTime() - now.getTime();
if (diff < 0) { // is after 5:25
diff += 24 * 60 * 60 * 1000; // refresh next day
}
setTimeout(location.reaload, diff);