removeEventListener不知道该函数 [英] removeEventListener without knowing the function

查看:1053
本文介绍了removeEventListener不知道该函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

部分第三方插件会将 eventListener 附加到网站中。如何在不知道附加的函数的情况下删除eventListener。

Some of the third party plugin will attach the eventListener into the site. How to I remove the eventListener without knowing the function that attached.

我这是指 removeEventListener 但我无法找到任何删除它的线索。

I refer this removeEventListener but I can't get any clue to remove this.

例如: getEventListeners(窗口)显示附加的事件。但是,当我尝试使用删除事件时,window.removeEventListener(eventname)在不知道该功能的情况下无法正常工作。

Eg: getEventListeners(window) shows the events attached. But, when I try to remove the event using window.removeEventListener("eventname") is not working without knowing that function.

请帮助,提前致谢。

推荐答案

getEventListeners(窗口)将返回事件地图及其注册事件监听器。

getEventListeners(window) will return a map of events and their registered event listeners.

因此,对于 DOMContentLoaded 事件,您可以拥有许多事件监听器。如果您知道要删除的侦听器的索引(或者只存在一个),则可以执行以下操作:

So for DOMContentLoaded event for example you can have many event listeners. If you know the index of the listener you want to remove (or if there exists only one), you can do:

var eventlistener = getEventListeners(window)["DOMContentLoaded"][index];
window.removeEventListener("DOMContentLoaded", 
                           eventlistener.listener,
                           eventlistener.useCapture);

这篇关于removeEventListener不知道该函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆