Last active
January 2, 2017 12:39
-
-
Save jbbn/8d9df81e1ba3e36056c0e4f82a5a041e to your computer and use it in GitHub Desktop.
SNIPPET - Inactivity time
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
// 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