我有这个计时器(请参阅下面的代码)。只有当浏览器窗口为onFocus
时,我才能确保倒计时开始并保持倒计时?
(例如,如果用户打开另一个窗口,我希望它暂停。)
//Countdown
function timerCountdown()
{
x=100;
document.getElementById('timer1').value=x;
x=x-1;
t=setTimeout("timerCountdown()",1000);
if (c<-1)
{
document.getElementById('timer1').value='Go';
clearTimeout(t);
}
}
window.onblur = function() {
// Stop counting
}
window.onfocus = function() {
// Start counting
}