Automatically reload page at specified time

Asked

Viewed 53 times

1

I need a code for web (Wordpress) that forces the Reload of only the home page of the site at a certain time, this for all users, for example at 18:10hs

  • you can use a Chrome extension, but not on time, it recharges every few minutes

1 answer

1


Try the Javascript below:

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.