Skip to content

Instantly share code, notes, and snippets.

@bran921007
Created November 21, 2015 21:47
Show Gist options
  • Save bran921007/da54425cb00c20cdb3ea to your computer and use it in GitHub Desktop.
Save bran921007/da54425cb00c20cdb3ea to your computer and use it in GitHub Desktop.
Detectar si el usuario esta activo o inactivo - Idle javascript
<script>
var timeoutID;
function setup() {
this.addEventListener("mousemove", resetTimer, false);
this.addEventListener("mousedown", resetTimer, false);
this.addEventListener("keypress", resetTimer, false);
this.addEventListener("DOMMouseScroll", resetTimer, false);
this.addEventListener("mousewheel", resetTimer, false);
this.addEventListener("touchmove", resetTimer, false);
this.addEventListener("MSPointerMove", resetTimer, false);
startTimer();
}
setup();
function startTimer() {
// wait 2 seconds before calling goInactive
timeoutID = window.setTimeout(goInactive, 1800000);
}
function resetTimer(e) {
window.clearTimeout(timeoutID);
goActive();
}
function goInactive() {
// do something
// alert("inactivo");
window.location.reload();
}
function goActive() {
// do something
startTimer();
}
</script>
@bereniicemorenno
Copy link

ghgfhg

@ivazquez-cmnrnk
Copy link

Genio!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment