Skip to content

Instantly share code, notes, and snippets.

@michaelNgiri
Last active October 9, 2021 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelNgiri/c91afadee2a57ff5ff0bf4aca85fce16 to your computer and use it in GitHub Desktop.
Save michaelNgiri/c91afadee2a57ff5ff0bf4aca85fce16 to your computer and use it in GitHub Desktop.
//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