Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get rid of the "Are you sure you want to leave this page" message?

How can I get rid of the "Are you sure you want to leave this page" message?

I try to use window.onBeforeunload=null and it works for Chrome, but it did not work for Firefox, Internet Explorer and Opera.

Thanks in advance.

like image 985
Ângelo Rigo Avatar asked Dec 20 '12 13:12

Ângelo Rigo


People also ask

How do you remove Are you sure you want to leave this page?

If you got the Are you sure you want to leave this page pop-up message, start a new Chrome window and click on the three-dot menu followed by More tools and Extensions. Now, turn off the toggle button next to all your extensions.

How do I remove a leave page in Firefox?

Chosen Solution hi DJSigma, to my knowledge you can only disable that behaviour globally: enter '''about:config''' into the firefox address bar (confirm the info message in case it shows up) & search for the preference named '''dom. disable_beforeunload'''. double-click it and change its value to '''true'''...


2 Answers

I'm not sure why your script is working in Chrome, all browsers should behave in the same way with this. Is it possible, that the code block where you remove the event listener, is for some reason executed only in Chrome?

Anyway, if you set window.onbeforeunload = someFunction; you can nullify it with window.onbeforeunload = null. However, if you set window.addEventListener('beforeunload', someFunction);, this event listener can't be removed with window.onbeforeunload = null. It can be removed only with removeEventListener('beforeunload', someFunction);.

If this answer doesn't help, please post all relevant code, like the snippet when assigning event listener, and also when trying to remove it.

like image 104
Teemu Avatar answered Oct 23 '22 14:10

Teemu


Using jQuery

$(window).off('beforeunload'); // tested in IE 11 and Chrome 62
like image 3
wickdninja Avatar answered Oct 23 '22 15:10

wickdninja