开发者

HTML DOM : How to get the whole list of registered event handlers? [duplicate]

This question already has answers here: How to find event listeners on a DOM node in JavaScript or in debugging? (20 answers) Closed 8 months ago.

For debugging purpose and memory leak, I'd like to have the full list of reg开发者_运维问答istered event handlers. There's this nice visual tool but a plain text list would be welcomed.


As the mentioned link says, there is no JavaScript API to retrieve all registered listeners. So, for testing purposes you might try overriding the EventTarget.prototype.addEventListener/removeEventListener methods and storing their arguments in your own storage to inspect later.

On a similar note, you can use the Chrome Developer Tools to examine currently registered listeners for a particular node (or the node chain up to the document root) in the Elements panel ("Event Listeners" section in the sidebar.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜