title: How to call window.close function only for tab or browser closing
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser">javascript detect browser close tab/close browser</a>  </p>
  </blockquote>
  
  
  
  <p>I wrote a window closing function given below</p>
  
  <pre><code>window.onunload = function() {
      confirmBox();
  }
  
  function confirmBox(){     
      var con = confirm("Do you want to delete session and cookies?");
      if(con == true)
          logout();
  }
  </code></pre>
  
  <p>There are three times the function called. </p>
  
  <p>1) when refresing the page,<br>
   2) when go to another link within that site and<br>
   3) when the browser or tab will closed.</p>
  
  <p>I just want the 3rd one. That is I want to call the window.close function or want to show the confirm box only when the tab or browser will closed.</p>
  
  <p>Can anyone suggest how to accomplish this?</p>