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 に答える