Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在一天中的特定时间刷新网页_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript 在一天中的特定时间刷新网页

Javascript 在一天中的特定时间刷新网页,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,我想在一天中的特定时间重新加载/刷新(WordPress)网页。因此,您无法使用或javascript函数setInterval()执行精确/特定的间隔 例如,我只想在以下时间重新加载页面: 08:30 09:00 09:15 14:20 我想用PHP或jQuery/JavaScript解决这个问题 我的代码示例(WordPress): 有什么建议吗?根据关于SO()的另一个答案,您可以编写如下函数: function refreshAt(hours, minutes, seconds)

我想在一天中的特定时间重新加载/刷新(WordPress)网页。因此,您无法使用
或javascript函数
setInterval()
执行精确/特定的间隔

例如,我只想在以下时间重新加载页面: 08:30 09:00 09:15 14:20

我想用PHP或jQuery/JavaScript解决这个问题

我的代码示例(WordPress):



有什么建议吗?

根据关于SO()的另一个答案,您可以编写如下函数:

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(18,45,0); //Will refresh the page at 18:45pm

我认为,您必须使用javascript而不是PHP来实现这一点,因为PHP是服务器端的,只能在页面加载时执行。我最近制作了一个网站,除了在特定时间播放警报而不是刷新页面外,它还做了一些类似的事情。基本上,它只是一个javascript计时器,每分钟检查一次时间,如果是我数据库中列出的特定时间,它就会发出警报。你也可以通过页面刷新而不是声音来实现这一点。如果你完全从另一个答案中复制了一个答案,并将其作为自己的答案发布,而只是提到它来自另一个答案,但没有实际链接到它,这可能是重复的,或者看起来有点不公平。似乎如果答案几乎完全相同,就应该标记为重复,是吗?对于未来的读者来说,最初的答案是非常真实的@GrumpyCrouton,我已经更新了答案。我会考虑自己的话,联系未来的答案。
refreshAt(18,45,0); //Will refresh the page at 18:45pm