gpt4 book ai didi

javascript 无法从列表中删除 onbeforeunload 事件监听器

转载 作者:行者123 更新时间:2023-12-01 02:31:47 29 4
gpt4 key购买 nike

我尝试了所有可能的方法来从 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

当我输入 getEventListener(window) 时仍然存在

enter image description here

有人知道另一种方法还是我做错了什么?

最佳答案

前导“on”仅在事件监听器作为对象属性访问时使用。删除事件时,只需使用事件名称:

 window.removeEventListener('beforeunload', carol, true);

关于javascript 无法从列表中删除 onbeforeunload 事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48266264/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com