Skip to content

Instantly share code, notes, and snippets.

@jbbn
Last active January 2, 2017 12:39
Show Gist options
  • Save jbbn/8d9df81e1ba3e36056c0e4f82a5a041e to your computer and use it in GitHub Desktop.
Save jbbn/8d9df81e1ba3e36056c0e4f82a5a041e to your computer and use it in GitHub Desktop.
SNIPPET - Inactivity time
// http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly
var inactivityTime = function () {
var t;
window.onload = resetTimer;
// DOM Events
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function logout() {
alert("You are now logged out.")
//location.href = 'logout.php'
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 3000)
// 1000 milisec = 1 sec
}
};
/*
document.onload = resetTimer;
document.onmousemove = resetTimer;
document.onmousedown = resetTimer; // touchscreen presses
document.ontouchstart = resetTimer;
document.onclick = resetTimer; // touchpad clicks
document.onscroll = resetTimer; // scrolling with arrow keys
document.onkeypress = resetTimer;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment