Submit form when onUnload fired
<p>Simple question (probably), but I'm buggered if I can find an answer...</p>

<p>I have a back-end CGI application and a number of dynamically-created webpages (plain ol' HTML+JS+CSS), each with a single form. In every form, in addition to a number of other submit buttons, there is a closeApplication button, which, when clicked, causes the page to be submitted and the CGI application to perform some cleanup processing.</p>

<p>Sometimes however, once thy've done their work, users being what they are (idiots), they don't bother to press the closeApplication button, and simply close the browser window.</p>

<p>I've been trying to figure out how to automatically 'fire' the closeApplication button if the user does this, by using the onUnload handler, but I can't seem to find out how to determine whether the user is closing the browser window/tab or simply submitting the page.</p>

<p>Is there a way within the onUnload handler to find this out?</p>

<p>p.s. I'm just using basic JS - no JQuery or other framework, but I doubt that matters...</p>
