Created
April 7, 2020 11:27
-
-
Save mhmda-83/fe546bc3bd2849003f7d34dd03e68067 to your computer and use it in GitHub Desktop.
check how much time user spend out of website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timer = 0; | |
let interval; | |
document.addEventListener('visibilitychange', () => { | |
if (document.visibilityState === 'visible') { | |
alert(timer); | |
clearInterval(interval); | |
timer = 0; | |
} else { | |
interval = setInterval(() => timer++, 1000); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment