jTimeout
by HTMLGuy, LLC (https://htmlguy.com)
Demo
https://htmlguyllc.github.io/jTimeout/
What is it?
jQuery session timeout handler - Tracks a user's session expiration and lets them know before their session times out so they can extend it. Then tells them when it has expired so they can login again. The only time the timer isn't reset but could/should be, is when an AJAX call is made to a page that doesn't include jTimeout. You'll have to just call "$.jTimeout.reset(1440);" each time an AJAX call is made to reset the timer. Passing the number of seconds is optional, it'll default to the $.jTimeout.defaults.timeoutAfter param. If you don't implement this reset, no big deal. The session doesn't actually have to be expired for this plugin to work. It'll manually call the logout page on timeout.
Dependencies
- jQuery
- jAlert (unless you override the callbacks) :: available here: https://github.com/HTMLGuyLLC/jAlert
Available on NPM
https://www.npmjs.com/package/jtimeout
npm install jtimeout
How to use
<!-- your site content --> <!-- Include jQuery --> <!-- Include jAlert - Get it here: https://github.com/HTMLGuyLLC/jAlert --> <!-- Include this Plugin -->
Options
;
Seting the default session length in PHP (recommended)
$
How to reset the expiration
$;
How to set the timer to a specific number of seconds
$;
Recommended reset usage
Everytime you request a page that extends a user's session, use the reset function:
;//warning: If $.ajax() or $.ajaxSetup() is called with the global option set to false, the .ajaxStop() method will not fire.
If you want to use your own modal
jTimeout already works out of the box with jAlert, but can fairly easily configured to work with your own custom callbacks. Just override the callbacks like this:
$;