title: Jasvascript : Alert notification after inactivity and logging out after 5 more minutes
body: <p>I have a little problem regarding browser window closing,</p>
  
  <p>Basically, I have a page which I want to close after 15 minutes of inactivity. I alraeady managed to make a timer that will alert the window after inactivity for 10 minutes.</p>
  
  <p>What I need is that on timer finish, a popup/alert with a visible countdown comes up and from here the user can either continue with his session or end it. If the user does not click on continue or ignore the popup for 5 more minutes, both the popup and parent window will close. Else if the user presses continue the popup will close and the main page is refreshed (and thus starting the timer again) Any suggestions? Here is my code:</p>
  
  <pre><code>    var idleTime = 0;
      var activeTime = 0;
      var warningFlag = 0;
      var loginTime = new Date();
      var logoutTime = loginTime;
      setInterval(function checkIdle() {
          idleTime += 1;
          activeTime += 1;
            if(idleTime &gt; 10) {
              alert("You've been inactive for 10 \n minutes, are you still there ?\nYou logged in at " + loginTime);
              warningFlag=1;
          }
          if((idleTime &gt; 15) &amp;&amp; (warningFlag==1)) {
              alert("You've been logged out due to inactivity for 15 \n minutes? \nYou logged out at " + logoutTime);
              window.close();
          }
          window.onload = resetTimer;
          document.onmousemove = resetTimer;
          document.onkeypress = resetTimer;
      },1000);
  
      function resetTimer() {
           idleTime = 0;
      }
  </code></pre>