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

3

10

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.

Lusterware answered 20/12, 2012 at 13:21 Comment(3)
Where are you seeing this? Is this a page you wrote? If so, can you post some relevant code?Deflect
window.,onBeforeunload=null is invalid syntax btw. Probably just a typo in your post, but if you ask a question, please take the time to make sure that the information you provide is correct.Watercraft
how is beforeunload working Opera at all?Retrogress
H
16

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.

Harmonium answered 20/12, 2012 at 18:46 Comment(1)
$attrs = array('onchange' => 'javascript:this.form.submit();window.onbeforeunload=null;onUnload=null'); $mform->addElement('select', 'teacher', 'Teachers', $result, $attrs);Assimilate
B
4

Using jQuery

$(window).off('beforeunload'); // tested in IE 11 and Chrome 62
Bookman answered 21/11, 2017 at 15:30 Comment(1)
I was unsuccessful using the accepted answer, and jQuery was already available on the page.Bookman
M
-13

Clear my browsing history, seemed to help.

Maymaya answered 22/1, 2014 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.