0

I want the script which can display the custom message to the user when it exits from the page in the firefox browser. Firefox is showing its default message even after using custom message, though chrome is showing it correctly. But i want to display this custom message in firefox also

 window.onbeforeunload = function() {

   return 'Are you sure.';
 }
Atul Prajapati
  • 177
  • 1
  • 11
  • 1
    Is this what you're looking for? http://stackoverflow.com/questions/333665/javascript-to-get-an-alert-when-closing-the-browser-window – test Aug 24 '15 at 15:04
  • I am asking for firefox, this message is displayed in chrome not in firefox , first check yourself. is really this message displays in firefox? – Atul Prajapati Aug 24 '15 at 15:21

1 Answers1

2

It appears they disabled it on purpose: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

In Firefox 4 and later the returned string is not displayed to the user. Instead, Firefox displays the string "This page is asking you to confirm that you want to leave - data you have entered may not be saved."

See this related question for potential workarounds, but all are pretty messy:

Firefox 4 onBeforeUnload custom message

Community
  • 1
  • 1
DasBeasto
  • 2,082
  • 5
  • 25
  • 65
  • But is there any way to hack this? – Atul Prajapati Aug 24 '15 at 15:22
  • I only tried [the second answer](http://stackoverflow.com/a/9866486/2070057) in that linked question and it prompted the user with the custom message surrounded by default messaging like "this page is prompting etc..." and followed up by their default prompt as well. So as far as I can tell even hacky solutions aren't going to improve this experience but maybe someone else will have a better solution. – DasBeasto Aug 24 '15 at 15:25
  • It's a security issue. If you find a "hack", they'll fix it and the hack will stop working. – Pointy Aug 24 '15 at 15:27