Search code examples
javascripthttp-redirecttimeoutdom-eventsuser-inactivity

Redirect user after 60 seconds of idling/inactivity?


How can I use JavaScript on my site to redirect the user to a /logout page after 60 seconds of inactivity?

I know setting a timer or using a meta refresh tag is straightforward: but I only want to redirect inactive users, not disrupt someone's active session/usage.

Is this possible with JavaScript?


Solution

  • I belive you are looking for something like this:
    http://paulirish.com/2009/jquery-idletimer-plugin/

    If you were to code that yourself, you would need to capture mouse and keyboard events and restart your timer after any of these events. If the timer ever reaches the threshold or counts down to 0 from the threshold you can reset the URL of the page.