Javascript Countdown Timer
Hello heroes!
I'm trying to create a Javascript countdown timer that starts at 02:30:00 and when the remaining time is over, the course is complete.
However, i'm facing this problem: everytime the learner refreshes the browser tab or leaves the course, the timer either stops or restart the count. What I need is: even if the page is refreshed, the timer continues to count down. Is it possible?
Can I use cookies to storage the values? If positive, how can I do that?
Javascript masters can help me, please?
Here's my code (I'm super newbie to JS, sorry if my code is bad):
------
var player = GetPlayer();
// Set the date we're counting down to
var countDownDate = new Date();
countDownDate.setMinutes (countDownDate.getMinutes() + 150);
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var hh = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
player.SetVar("hours", hh);
var mm = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
player.SetVar("minutes", mm);
var ss = Math.floor((distance % (1000 * 60)) / 1000);
player.SetVar("seconds", ss);
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
return;
}
var totalTime = hh + ':' + mm + ':' + ss;
player.SetVar("Countdown_Display",totalTime);
}, 1000);
------
If it helps, my story file is attached too. I'm manupulating everything by the slide master.