Jquery task when user closes window or browser
<p>I am trying to send a post to my server when a user either closes their browser or closes a window.</p>

<p>This is what I have so far:</p>

<pre><code> $(window).unload(function(){
    $.post('/offline', {account_id: ACCOUNT_ID});
});
</code></pre>

<p>However, this only seems to work when a user enters a new url in the current window.</p>

<p>In addition to whenever a user enters a new url in a window, I need to send a post to the server when the browser or window is closed.</p>

<p>Anyone know what the problem is?</p>

<p>Thank you.</p>

<p>Update:</p>

<p>I think the above javascript will work for me, however, this occurs for every event on the website.  For example, clicking a link.</p>

<p>Is it possible to to only trigger this if a user enters a new url or closes the window?</p>
