Session Timeout And Keep-alive Plugin With jQuery - sessionTimeout

File Size: 8.77 KB
Views Total: 26011
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Session Timeout And Keep-alive Plugin With jQuery - sessionTimeout

sessionTimeout is a useful jQuery plugin that popups a timeout dialog with 'Log out' and 'keep Alive' options after a certain idle time. If 'Log Out' is clicked, the page is redirected to a specified URL. If 'Keep Alive' is clicked, a keep-alive URL is requested through AJAX. If no options is selected after another set amount of time, the page is automatically redirected to a timeout URL.

Basic usage:

1. Include the jQuery sessionTimeout.js script after you've loaded jQuery JavaScript library.

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="jquery.sessionTimeout.js"></script>

2. Include jQuery UI's JavaScript and CSS for the session timeout dialog.

<link rel="stylesheet" href="jquery-ui.min.css">
<script src="jquery-ui.min.js"></script>

3. Initialize the plugin on document ready. In this case, the plugin will display a warning dialog after 3 seconds and automatically redirect the page after 30 seconds.

$.sessionTimeout({
  warnAfter: 3000,
  redirAfter: 30000
});

4. More configuration options.

$.sessionTimeout({

  // custom warning message
  message: 'Your session is about to expire.',

  // keep alive url
  keepAliveUrl: '/keep-alive',

  // request type
  keepAliveAjaxRequestType: 'POST',

  // redirect url
  redirUrl: '/timed-out',

  // logout url
  logoutUrl: '/log-out',

  // 15 minutes
  warnAfter: 900000, 

  // 20 minutes
  redirAfter: 1200000, 

  // appends time stamp to keep alive url to prevent caching
  appendTime: true 
  
});

This awesome jQuery plugin is developed by travishorn. For more Advanced Usages, please check the demo page or visit the official website.