Session Timeout And Keep-alive Plugin With jQuery – sessionTimeout

Session Timeout And Keep-alive Plugin With jQuery – sessionTimeout

sessionTimeout is an 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="//"></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.

  warnAfter: 3000,
  redirAfter: 30000

4. More configuration options.


  // 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 


Author Surjit Sidhu

Surjit SidhuSurjit is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling.