1
我有一个网站,我想每五分钟在特定的时间范围内重新加载。时间,如每隔五分钟从上午9点到中午12点。我怎么做?给定时间范围内的刷新页面
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(15,35,0); //Will refresh the page at 3:35pm
下面只是在给定时间
你应该在你的代码中使用的setInterval,否则跳过一个刷新,仅此而已。但是,只要你不关心其他时间的不活动 - 没关系。 – Cheery 2012-02-07 06:37:16
哎呀我的错误我已修复。谢谢。 – Daniel 2012-02-07 06:38:16