JillElaine / jquery-idleTimeout

Idle activity timeout and logout redirect for jQuery for multiple windows & tabs
Other
73 stars 79 forks source link

jquery-idleTimeout

November 2021: Please note, I am no longer able to maintain this code. When I wrote the code, I used clear naming conventions and numerous comments to make it easy for others to follow and modify the code. The code, as it is at this point in time, is untested on the most recent browsers, and needs to have some bugs fixed.

IF YOU WANT TO TAKE OVER OWNERSHIP OF THIS REPOSITORY:

Please read https://docs.github.com/en/repositories/creating-and-managing-repositories/transferring-a-repository and let's do it!

Highly configurable idle (no activity) timer and logout redirect for jQuery.

Functions across multiple browser windows, tabs and, optionally, iframes (single or nested) as long as the iframes meet the 'Same-Origin Policy'.

Listed on NPM and JQuery's Plugin site.

Requires Marcus Westin's store.js which uses localStorage, globalStorage and userData behavior to 'communicate' across multiple browser windows & tabs without cookies or flash.

Basic Demo Page and Iframes Demo Page

Informative Wiki Pages!

Communication Across Multiple Browser Windows, Tabs and Iframes

Required Dependencies

Functionality

If the warning dialog box is enabled:

Warning Dialog

If the warning dialog box is disabled:

How to Use

For lots more information, please read the Wiki

Detailed information on all the Public Configuration Variables.

Example Usage Page

Example Basic Document Ready Function

  $(document).ready(function () {
    $(document).idleTimeout({
      redirectUrl:  '/logout' // redirect to this url. Set this value to YOUR site's logout page.
    });
  });

Example Site Logout Button

If user voluntarily logs out of your site with your 'Logout' button (instead of timing out), you can force all 'same domain' windows and tabs to log out too! Attach this small snippet of code, $.fn.idleTimeout().logout();, to the 'onclick' function of your site's 'Logout' button. See example below.

<input value="Logout" onclick="$.fn.idleTimeout().logout();" type="button" title="Logout ALL Windows & Tabs" />

Iframe Information

If you require activity detection within iframes, use the jquery-idleTimeout-iframe.min.js script.

Please read the Iframe Wiki Page.

Troubleshooting

Please read the Troubleshooting Wiki Page

Possible 'mousemove' bug with Chrome browser (on Windows?)

User g4g4r1n reports 'mousemove' event sometimes fires when mouse is not moving on Chrome browser and offers a possible solution.

Your suggestions and bug reports are appreciated

Use jquery-idleTimeout-for-testing.js with Firefox with Firebug add-on or similar for debugging. Your feedback helps to improve this plugin!