How to tell the difference between a page refresh and closing a page
<p>I have a web app game and while in the game I want to have it so if a user closes the page or their browser, it will automatically log them out. I tried using the onbeforeunload event attached to the window:</p>

<pre><code>window.onbeforeunload = function() {
    // perform logout functions here
}
</code></pre>

<p>The problem is, that will also fire if the user refreshes the page. Is there a way I could detect whether or not the user is completely closing the whole page, or just refreshing it?</p>
