Answer the question
In order to leave comments, you need to log in
How to make the stopwatch not stop when switching to another tab?
Hello everyone, there is such a code:
How to make the stopwatch work correctly when switching to another browser tab and then returning.
Answer the question
In order to leave comments, you need to log in
The logic is like this.
When creating a timer, get its start time and write it to localStorage, when determining the inactive state of the page, write this time there as well. And when you return, having calculated the time difference, you continue to count from the right moment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question