最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin13浏览0评论

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.

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.

Share Improve this question edited Dec 20, 2012 at 13:23 Paul D. Waite 98.8k57 gold badges202 silver badges271 bronze badges asked Dec 20, 2012 at 13:21 Ângelo RigoÂngelo Rigo 2,15910 gold badges40 silver badges73 bronze badges 3
  • 10 Where are you seeing this? Is this a page you wrote? If so, can you post some relevant code? – RonaldBarzell Commented Dec 20, 2012 at 13:22
  • 2 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. – Felix Kling Commented Dec 20, 2012 at 13:23
  • how is beforeunload working Opera at all? – c69 Commented Dec 21, 2012 at 23:48
Add a comment  | 

3 Answers 3

Reset to default 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.

Using jQuery

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

Clear my browsing history, seemed to help.

发布评论

评论列表(0)

  1. 暂无评论