Forum Discussion
ChristinaClark-
27 days agoCommunity Member
Javascript timer stops if browser tab is minimized
I have several storyline projects that use a javascript countdown timer so that certain activities are completed in a certain time.
I've noticed that in some browsers, the timer stops if you minimize a tab, in others, the countdown continues. I want it always to continue. I believe it has something to do with browser throttling???
Any ideas how I could make sure the timer never stops, even if the tab/window is minimized?
Here's the existing code (made using Matthew Bibby's excellent but sadly defunct website):
function zeros(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
var minutes, seconds, timer, totalTime;
var counter = setInterval(timer, 1000);
var fin="Done";
var player = GetPlayer();
var count = player.GetVar("Countdown_Duration");
function timer() {
count = count - 1;
minutes = zeros(Math.floor(count / 60));
seconds = zeros(count - minutes * 60);
if (count == 0){
player.SetVar("Countdown_Finished",fin);
}
if (count < 0) {
clearInterval(counter);
return;
}
totalTime = minutes + ':' + seconds;
player.SetVar("Countdown_Display",totalTime);
}
Thank you for any help!
C.
No RepliesBe the first to reply