Answer the question
In order to leave comments, you need to log in
The countdown timer breaks if you re-enter the site, how to make the timer count down again when you re-enter?
Good afternoon, in general, there is a flipclock countdown timer with cookies, that is, the time does not reset when you reload or close the tab, but continues to go and after the timer expires, it starts again.
Essence of the question:
let's say if there are 10 seconds left until the end of the timer and at this time close the tab with the site and wait more than 10 seconds (for the timer to finish counting and start again) and go to the site again, then the timer gives an error and stops working. I tried this and that, it still does not work, and I realized that it would not hurt to get help from the outside to figure out what was wrong in the code.
Here is a link to jsfiddle
Here is the same code, just uploaded it to my host
Answer the question
In order to leave comments, you need to log in
Timer keeps counting down when tab is closed
https://jsfiddle.net/vwzjkbtg/5/
init: function () {
if ( Date.now() > $.cookie("endDate") ) {
$.removeCookie("endDate");
}
if (!$.cookie("endDate")) {
var t = Date.now() + 10000;
$.cookie("endDate", Math.round(t / 1e3))
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question