Skip to content

Instantly share code, notes, and snippets.

@jtreitz
Created June 26, 2014 12:46
Show Gist options
  • Save jtreitz/7fb95b24d072913d526f to your computer and use it in GitHub Desktop.
Save jtreitz/7fb95b24d072913d526f to your computer and use it in GitHub Desktop.
Auto logout on inactivity (works across tabs)
$ ->
IDLE_TIMEOUT = 120
CheckIdleTime = ->
if (new Date() - Date.parse(window.localStorage.getItem('IDLE')) >= IDLE_TIMEOUT*1000)
$("#logout-button").trigger "click"
document.onkeydown = document.onmousemove = document.onclick = ->
window.localStorage.setItem('IDLE', new Date())
window.setInterval CheckIdleTime, 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment