0

我有这个计时器(见下面的代码)。仅当浏览器窗口为时,我如何确保倒计时开始并继续倒计时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);

    }
}
4

1 回答 1

1
window.onblur = function() {
  // Stop counting
}

window.onfocus = function() {
  // Start counting
}
于 2012-03-06T03:20:17.733 回答