The onbeforeunload
event[
^] works in all desktop browsers, including the latest version of Firefox.
However, both Chrome
(since v51), Firefox
(since v44), and Safari
(since v9.1) will replace your custom message with a standard message for "security reasons".
The only workaround is to try to hook any events that will result in the user leaving the page, and display your message
before the browser handles the event. This can get very complicated, as you need to handle form submission, clicks on
<a>
elements
(but not those that open in a new window, or trigger an in-page action), etc.