Ângelo Rigo
Ângelo Rigo

Reputation: 2157

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.

Upvotes: 10

Views: 31957

Answers (3)

wickdninja
wickdninja

Reputation: 1039

Using jQuery

$(window).off('beforeunload'); // tested in IE 11 and Chrome 62

Upvotes: 4

user57510
user57510

Reputation: 1

Clear my browsing history, seemed to help.

Upvotes: -13

Teemu
Teemu

Reputation: 23406

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.

Upvotes: 16

Related Questions