Top Ad unit 728 × 90

How to synchronize jQuery idle timeout in multiple tabs?




I had the same issue! An idle timer can communicate (stay in sync) across multiple tabs using localStorage variables. Most modern browsers support this feature. On github, store.min.js provides good functionality with 'fallback' behavior for older browsers.

Here is the 'testing' code for an idleTimer plugin which provides synchronized windows/tabs (must all be within the same browser and domain). It sets 2 localStorage variables to track the state of the user's session.

You can try this code and check Opening multiple tabs in the same browser and observe.

jquery-idleTimeout.js

In your html file, before the end body tag code the following:
<script src="<?php echo PATH; ?>/plugins/idletimeout/store.min.js" type="text/javascript"></script>
  <script src="<?php echo PATH; ?>/plugins/idletimeout/idletimeout.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(document).ready(function (){
      $(document).idleTimeout({
      redirectUrl: '../../log_out.php', // redirect to this url on logout. Set to "redirectUrl: false" to disable redirect
      // idle settings
      idleTimeLimit: 1800, // 'No activity' time limit in seconds. 1200 = 20 Minutes
      idleCheckHeartbeat: 2, // Frequency to check for idle timeouts in seconds
      // optional custom callback to perform before logout
      customCallback: false,  // set to false for no customCallback
      // customCallback:    function () {    // define optional custom js function
          // perform custom action before logout
      // },

      activityEvents: 'click keypress scroll wheel mousewheel mousemove', // separate each event with a space
      // warning dialog box configuration
      enableDialog: true,           // set to false for logout without warning dialog
      dialogDisplayLimit: 180,       // 20 seconds for testing. Time to display the warning dialog before logout (and optional callback) in seconds. 180 = 3 Minutes
      dialogTitle: 'Session Expiration Warning', // also displays on browser title bar
      dialogText: 'Because you have been inactive, your session is about to expire.',
      dialogTimeRemaining: 'Time remaining',
      dialogStayLoggedInButton: 'Stay Logged In',
      dialogLogOutNowButton: 'Log Out Now',

      errorAlertMessage: 'Please disable "Private Mode", or upgrade to a modern browser.',
      // server-side session keep-alive timer
      sessionKeepAliveTimer: 600,   // ping the server at this interval in seconds. 600 = 10 Minutes. Set to false to disable pings
      sessionKeepAliveUrl: window.location.href // set URL to ping - does not apply if sessionKeepAliveTimer: false
      });
    });
  </script>
How to synchronize jQuery idle timeout in multiple tabs? Reviewed by Ashok Sen on 17:07:00 Rating: 5

No comments:

Website Design Company at Kolkata All Rights Reserved © 2014 - 2019
Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.