Javascript cookie expiration/deletion on different browsing scenarios
<p>A client requested cookie functionality where if the browser is not closed, the cookie has a 30 minute expiration, but then it needs to be removed if/when a user closes the browser.</p>

<p>Here's how I was going to do it:  </p>

<pre><code>delCookie = function() {
    document.cookie = 'cookieName=;expiration=Thu, 01-Jan-70 00:00:01 GMT;';
};

$(window).unload(function() {
    delCookie();
})
</code></pre>

<p>I then realized that when user navigates to a different site, it also triggers .unload which will delete the cookie instead of keeping the cookie with expiration.  </p>

<p>Is there any way I can detect using javascript when browser is being closed or a user is navigating away from the site?</p>
