如何在特定时间自动重新加载网页?

14 html javascript reload

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

And*_*ore 50

以下JavaScript代码段允许您在给定时间刷新:

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);
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以添加脚本标记来调用该refreshAt()函数.

refreshAt(15,35,0); //Will refresh the page at 3:35pm
Run Code Online (Sandbox Code Playgroud)


Sor*_*tis 6

<META HTTP-EQUIV="Refresh" CONTENT="5">
Run Code Online (Sandbox Code Playgroud)

这将迫使页面每5秒重新加载一次.只需计算正确的间隔并将其添加到内容标记

  • **@ Sorantis:**服务器端的问题是时区不同,并且您并不总是拥有客户端的信息. (4认同)
  • 问题是关于具体时间而不是时间间隔 (3认同)