Submit form when onUnload fired
Simple question (probably), but I'm buggered if I can find an answer...
I have a back-end CGI application and a number 开发者_StackOverflow中文版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.
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.
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.
Is there a way within the onUnload handler to find this out?
p.s. I'm just using basic JS - no JQuery or other framework, but I doubt that matters...
Unfortunately, you're out of luck.
This question covers very similar ground: how to identify onbeforeunload was caused by clicking close button
What you could possibly do is store a variable when anything valid is clicked on your page that would navigate away, then check that in your onunload
handler - if it's false
(or whatever), then assume that they've closed the window and submit. I think this would probably be flaky though.
精彩评论