title: User session management using Javascript
body: <p>I have one session timer in my application which checks if the user is idle for a specific time. Below is my code.</p>
  
  <pre><code>var sessionTimeout;
  window.onload = resetTimer;
  // DOM Events
  document.onmousemove = resetTimer;
  document.onkeypress = resetTimer;
  // I have some more dom events here
  
  function logout() {
      alert("You are now logged out.")
      //location.href = 'logout.php'
  }
  function resetTimer() {
      clearTimeout(sessionTimeout);
      sessionTimeout = setTimeout(logout, 30000)
  }
  </code></pre>
  
  <p>If the user opens two tabs simultaneously and keeps the one tab idle and other not, he will be logged out after the timeout period because the timer will run in the other tab which is not in focus. Is there any way to handle this? I think Javascript can't access the data in the other tabs. So is there any global timeouts specific to the browser which applies to all tabs so that the session will be active if any tab is not idle? Can anyone suggest solutions?</p>