Last active
October 9, 2021 10:37
-
-
Save michaelNgiri/c91afadee2a57ff5ff0bf4aca85fce16 to your computer and use it in GitHub Desktop.
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
//initialize the function once the page loads | |
window.onload = function() { | |
activateTimer(); | |
} | |
//show the popup if the user is idle for more than 15 seconds | |
// the user is considered idle if he doesn't actively interact | |
//with the page by either moving his cursor or pressing any button on the keyboard | |
const activateTimer = ()=> { | |
let time; | |
window.onload = resetTimer; | |
document.onmousemove = resetTimer; | |
document.onkeydown = resetTimer; | |
function popSomething() { | |
alert("show popup now") | |
} | |
function resetTimer() { | |
clearTimeout(time); | |
time = setTimeout(popSomething, 10000) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment