Skip to content

Instantly share code, notes, and snippets.

@framon
Created November 12, 2013 15:02
Show Gist options
  • Save framon/7432287 to your computer and use it in GitHub Desktop.
Save framon/7432287 to your computer and use it in GitHub Desktop.
Basic jQuery to detect idle time. TODO: Improve
idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 19) { // 20 minutes
window.location.reload();
}
}
@lowzijian
Copy link

how do i implement it?

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