browser event handling-only browser/tab close
<p>I need to capture the event of the user closing the browser or tab or going to a different site before the last page of the application so that the PHP session can be unset and database transactions made up to this point can be undone. I have been searching for days and the closest thing I have found is using event.clientX and event.clientY to get the cursor position and eliminating the specific locations of the back, forward, submit, and refresh buttons from my onbeforeunload code. However, this does not seem reliable since the window might not always be the same size for every user. Can anyone help? </p>

<p></p>

<pre><code>function beforeUnloadAction(event)
{
     if(event = browser close, tab close, go to a different site)
     {
          //unset the session, rollback database transactions
     }
     else 
     {
         //do nothing 
     }
}
</code></pre>