Skip to content

Instantly share code, notes, and snippets.

@zahedkamal87
Forked from gerard-kanters/inactivity.js
Created October 31, 2018 10:49
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 zahedkamal87/a6e4752d7a07ac467dd99d9861e94d95 to your computer and use it in GitHub Desktop.
Save zahedkamal87/a6e4752d7a07ac467dd99d9861e94d95 to your computer and use it in GitHub Desktop.
Inactivity timeout javascript
<script type="text/javascript">
function idleTimer() {
var t;
//window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
function logout() {
window.location.href = '/action/logout'; //Adapt to actual logout script
}
function reload() {
window.location = self.location.href; //Reloads the current page
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 1800000); // time is in milliseconds (1000 is 1 second)
t= setTimeout(reload, 300000); // time is in milliseconds (1000 is 1 second)
}
}
idleTimer();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment