Wednesday, 2 October 2013

Prevent timer from stopping when window is inactive Javascript

Prevent timer from stopping when window is inactive Javascript

Helllo, I'm making a quiz application, and want to set a timer. I want to
make it in Javascript. This is my function:
function countDown(sec, elem) {
_(elem).innerHTML = sec;
if(sec < 1) {
clearTimeout(timer);
endGame ();
return;
}
sec--;
var timer = setTimeout('countDown('+sec+',"'+elem+'")',1000);
}
The problem is that, for example, for mobile Saffari browser, when you
hold your finger on the screen (like scrolling effect), the timer stops,
yet you can still see the questions... So, basically, you can have an
unlimited time. How can I make the timer to run nomatter what?
Thank you in advance!

No comments:

Post a Comment