Javascript alert when user closes the tab or the window
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6280202/javascript-alert-when-user-closes-the-tab-ot-the-window">Javascript alert when user closes the tab ot the window</a>  </p>
</blockquote>



<p>I want when user close the window (or the tab) or when he goes to another website different from my own, a confirm to pop up, and if he confirms to execute a ajax script and after that to close (or change the location). I'm using jQuery and <code>onbeforeunload</code> event, but I dont know how to capture what is the new location, or when the tab or window is closed. Please help.</p>
