I have this timer (see Code below). How can I make sure that the countdown starts AND keeps counting down only if the browser window is onFocus
?
(I want it to pause if the user opens another window, for example.)
//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);
}
}