19

I have a script that if user is uploading file and try to close the browser it will trigger the onbeforeunload() and popup an alert.. I change the message but somehow it does not work in firefox, it works perfectly fine on IE or opera or safari.. the code is something like

window.onbeforeunload = checkUnload;
function checkUnload() {

if (document.upload.isEmailing())
    return "Aaaa";

So, in IE and opera, when users close the browser during emailing, it will show pop up saying "AAAA" with leave or stay page button.

However, in firefox, it show

"This page is asking you to confirm that you want to leave - data you have entered may not be saved." with leave or stay page button.

Why it does not work, am I doing something wrong?

Note: FF I am using is the latest version if that will help.

Harts
  • 4,023
  • 9
  • 54
  • 93

2 Answers2

21

For security reasons, Firefox now ignores the string you return.
There is nothing you can do about it.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • So your answer @ http://stackoverflow.com/a/1632004/971459 is no longer useful? ..damn! – Samson Oct 26 '12 at 07:34
  • FF is the new IE -- insane! – rymo Jun 27 '13 at 15:52
  • 3
    @rymo: The security reasons make perfect sense. Malicious sites put all sorts of misleading text there. – SLaks Jun 28 '13 at 03:16
  • 8
    @SLaks: naturally these malicious sites wouldn't dare put misleading text in the content of the page itself, or in a separate `alert()` box - they know to save it all for the `onbeforeunload`. So I guess Mozilla's got us completely covered. Great Job! Phishing is SOLVED! – rymo Jun 28 '13 at 05:57
6

According to MDN:

Note that in Firefox 4 and later the returned string is not displayed to the user.

See the referenced bug for more info.

Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103