Do something before the user closes the tab/window
<p>I tried <code>window.onbeforeunload</code> but it doesn't seem to work. Any help?</p>

<p>I have a cookie that tracks if the user logged in.</p>

<pre><code>function handleLoginRegSuccess(){
    $.cookie('loginStatus', "ON", { expires: 1, path: '/'});
    showBusyMessage();
    goToIndex();
}
</code></pre>

<p>This is what I tried, but it doesnt work.</p>

<pre><code>window.onbeforeunload = function(e) {
    if(userLoginStatus()=="ON"){
        requestLogout();
        $.removeCookie('loginStatus');
        return "test";
    }
};
</code></pre>
