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.
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
customCallback
to add function(s) which execute just before user logoutIf the warning dialog box is enabled:
idleTimeLimit
amount of user inactivity, the warning dialog box with 2 buttons appear. Default button may be activated with mouse click or press of Enter key.dialogDisplayLimit
amount of time. If user remains idle, plugin will redirect to configured redirectUrl
.If the warning dialog box is disabled:
idleTimeLimit
amount of user inactivity, idleTimeout script will redirect to configured redirectUrl
.$(document).ready(function ()...
, function somewhere on your siteredirectUrl
variable within the 'document ready' function to redirect to your site's logout page$.fn.idleTimeout().logout()
For lots more information, please read the Wiki
Detailed information on all the Public Configuration Variables.
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" />
If you require activity detection within iframes, use the jquery-idleTimeout-iframe.min.js script.
Please read the Iframe Wiki Page.
Please read the Troubleshooting Wiki Page
User g4g4r1n reports 'mousemove' event sometimes fires when mouse is not moving on Chrome browser and offers a possible solution.
Use jquery-idleTimeout-for-testing.js with Firefox with Firebug add-on or similar for debugging. Your feedback helps to improve this plugin!