title: How to handle for browser refresh, back button
body: <ul>
  <li><p>I'm developing a site for internet banking system, once logged in I have main page(session is maintain here) and few tabs/links as child for the main page,</p></li>
  <li><p>I already have js to kill the session or to logout, but the problem is with the event handler</p></li>
  <li><p>when the page is refreshed or back button is click, I have to handle as below</p>
  
  <pre><code>window.onbeforeunload = function() {
     if( confirm("This page will be close") ){
           //called the logout fn to kill session
     }
  }
  </code></pre></li>
  <li><p>the above js works fine, but the problem with the above code is that its called whenever other links/tabs are clicked in the main page, so its keep on logout</p></li>
  <li><p>I'm sorry if my question is not clear or duplicate, do anyone can suggest the way to handle this</p></li>
  <li><p>for your info, I'm using jsp and servlet with js, this project cannot be used jquery and cannot disable back button and refresh button</p></li>
  </ul>
  
  <p>Thanks in advance!</p>