この質問は以前にすでに回答されていることは知っていますが、同様のコードを探していましたが、より長い (分) 間隔でした。私が行った検索では出てこなかったので、これが私が思いついたものであり、共有したいと思いました:
働くフィドル
Javascript
function checklength(i) {
'use strict';
if (i < 10) {
i = "0" + i;
}
return i;
}
var minutes, seconds, count, counter, timer;
count = 601; //seconds
counter = setInterval(timer, 1000);
function timer() {
'use strict';
count = count - 1;
minutes = checklength(Math.floor(count / 60));
seconds = checklength(count - minutes * 60);
if (count < 0) {
clearInterval(counter);
return;
}
document.getElementById("timer").innerHTML = 'Next refresh in ' + minutes + ':' + seconds + ' ';
if (count === 0) {
location.reload();
}
}
HTML
<span id="timer"></span>