Skip to content

Instantly share code, notes, and snippets.

@cmalexander
Forked from gerard-kanters/inactivity.js
Last active February 6, 2017 22:33
Show Gist options
  • Save cmalexander/8e3693e58e2b4e69932ff7661001c5ab to your computer and use it in GitHub Desktop.
Save cmalexander/8e3693e58e2b4e69932ff7661001c5ab 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 reload() {
window.location = self.location.href; //Reloads the current page
}
function resetTimer() {
clearTimeout(t);
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