0

This code snap from this post works on latest Chrome (v58), but not on Firefox (v53):

window.onbeforeunload = function () {
    return "Do you really want to close?";
};

On Chrome, when closing tab, an alert pops out. But on Firefox, tab just closes, no alert.

Why is that? And how to know window closing in Firefox?

Community
  • 1
  • 1
zhm
  • 3,513
  • 3
  • 34
  • 55
  • different browsers handle onbeforeunload slightly differently - see [documentation](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload) - note, you'll NEVER get your own message "Do you really want to close?" from appearing in the alert – Jaromanda X May 09 '17 at 02:33
  • @JaromandaX You are right. The message shown on Chrome alert is not the one I returned. But Firefox doesn't show any message before tab close, why? In document, I see Firefox should show message: *For example, Firefox displays the string "This page is asking you to confirm that you want to leave - data you have entered may not be saved."* BTW, the flag *dom.disable_beforeunload* is set to false. – zhm May 09 '17 at 02:57
  • did you read the [documented exmple](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#Example) – Jaromanda X May 09 '17 at 03:03
  • @JaromandaX Yes, I tested with this example too, alert shows on Chrome, but not on Firefox. – zhm May 09 '17 at 03:06
  • well, you must be doing it wrong - https://jsfiddle.net/kq0zpx9m/ (click run twice) - though, the fiddle isn't that reliable to be sure – Jaromanda X May 09 '17 at 03:08
  • @JaromandaX The fiddle works fine on Chrome (v58), but not Firefox (v53). I clicked run for a couple of times, no alert shown. :-( – zhm May 09 '17 at 03:17
  • Yeah it's odd. I'll check known code that worked in earlier versions and get back to you – Jaromanda X May 09 '17 at 03:19
  • @JaromandaX Sorry to bother, do you make any progress on this? – zhm May 18 '17 at 09:28

0 Answers0