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