如何在特定时间自动重新加载网页? [英] How to automatically reload a web page at a certain time?

查看:92
本文介绍了如何在特定时间自动重新加载网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我希望在特定时间重新加载,例如下午3:35,而不是像5分钟之后的特定时间间隔。我该怎么做?

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?

推荐答案

以下JavaScript代码片段可以让您在给定时间刷新:

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

然后你可以添加一个脚本标签来调用 refreshAt()函数。

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

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

这篇关于如何在特定时间自动重新加载网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆