[英]javascript cannot remove event listener onbeforeunload from list
I tried all possible ways to remove an event from window
object : 我尝试了所有可能的方法来从
window
对象中删除事件:
window.onbeforeunload = null;
window.BeforeUnloadEvent = null;
$(window).unbind('beforeunload');
$(window).off('onbeforeunload');
window.removeEventListener('beforeunload', carol, true);
window.removeEventListener('onbeforeunload', carol, true); // carol is that function see image below
and when i type getEventListener(window) is still present there 当我键入getEventListener(window)仍然存在
does anybody know another way or am i doing something wrong ? 有人知道另一种方式吗,或者我做错了什么?
The leading "on"
is only used when event listeners are accessed as object properties. 仅在将事件侦听器作为对象属性访问时才使用前导
"on"
。 When removing the event, just use the event name: 删除事件时,只需使用事件名称:
window.removeEventListener('beforeunload', carol, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.