V
V
Viktor2019-12-17 17:54:19
JavaScript
Viktor, 2019-12-17 17:54:19

How to make the stopwatch not stop when switching to another tab?

Hello everyone, there is such a code:
5df8ebdc609d6000679206.jpeg
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

1 answer(s)
S
Shohruh Shaimardonov, 2019-12-17
@polyak-888

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 question

Ask a Question

731 491 924 answers to any question