The back button event isn't captured by window.onbeforeunload
and isn't being handled by the onbeforeunload
handler.
There are a few questions on Stack Overflow asking about capturing the back button with no good answer but yet if a user hits the browser's back button while composing a new question on Stack Overflow a message box asking him to if he's sure he wants to continue pops-up.
This message box is different between Chrome and Firefox and feels native.
So, what's behind the curtains?
How can I have the browser popup a message box which gives the user the option to stay on the current page (like with onbeforeunload
)?
The back button event isn't captured by
window.onbeforeunload
and isn't being handled by theonbeforeunload
handler.
Not true. Check this test case with plain JavaScript - back button triggers the onbeforeunload
just fine. Checked with recent versions of all major browsers: Chrome 18, Firefox 11 and IE9. (Copy the link address, browse first to some other site then to the fiddle and hit the Back button)
So I fear your question is not really relevant - what you see is the browser native dialog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With