V
V
Vadim Stepanenko2018-03-18 02:23:00
JavaScript
Vadim Stepanenko, 2018-03-18 02:23:00

Why does the countdown timer slow down if the site tab is not active?

Hello everyone I
installed such a countdown on the site , but I noticed that if you open another tab of another site (do not close the tab of my site) and after 30 seconds open my tab, then the timer is not -30 seconds, from the value before switching to another tab , but much less. As far as I understand, the script freezes and when the tab in the browser is not active, it simply does not work. How can this be corrected?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
chromimon, 2018-03-18
@chromimon

Do you think it is correct that you occupy the user's resources for what he does not see ?
Lately, browsers have been limiting such things - both to save electricity in smartphones, and to avoid "miners in the browser", etc.
How to solve?
Update to the current time when the tab is activated.
And according to the mind - also stop when leaving the tab.

R
Ruslan., 2018-03-18
@LaRN

You can try to store not the value of the counter, but the time of the end moment. And on the counter to show the difference in seconds between the current time and the end. Then no frieze is terrible, as soon as the time comes out, the delta will become negative.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question