在IE中查看DOM级别2事件处理程序

时间:2021-10-08 03:18:20

Is there any way to view DOM level 2 event listeners added to a DOM element in IE 9+?

有没有办法在IE 9+中查看添加到DOM元素的DOM 2级事件监听器?

In Chrome, we can see attached events from console using getEventListeners(object).

在Chrome中,我们可以使用getEventListeners(object)查看来自控制台的附加事件。

I tried Visual Events, but it only displays DOM level 0 events.

我尝试了Visual Events,但它只显示DOM 0级事件。

In case if you are wondering, I need to list the attached event handlers to window unload event and debug which events are fired to find out which one is causing an exception/preventing propagation. The unload event handler is getting dispatched properly in Chrome.

如果您想知道,我需要列出附加的事件处理程序到窗口卸载事件并调试触发哪些事件以找出导致异常/阻止传播的事件。 unload事件处理程序正在Chrome中正确分派。

1 个解决方案

#1


2  

Yes, you can easily see DOM2 handlers:

是的,您可以轻松查看DOM2处理程序:

  • Right-click the element with the event handler and choose Inspect Element

    右键单击具有事件处理程序的元素,然后选择“检查元素”

  • That should trigger the DOM Explorer tab; if not, do so

    这应该触发DOM Explorer选项卡;如果没有,那就这样做

  • Pick the Events tab on the right-hand side

    选择右侧的“事件”选项卡

It lists the event handlers attached to the element, including DOM2 ones.

它列出了附加到元素的事件处理程序,包括DOM2。

For instance, using this fiddle:

例如,使用这个小提琴:

<div id="target">
I have a DOM2 event handler.
</div>

function thisIsADOM2Handler() {
    this.style.color = "green";
}
document.getElementById("target").addEventListener("click", thisIsADOM2Handler, false);

I followed the steps above to see this:

我按照上面的步骤看到了这个:

在IE中查看DOM级别2事件处理程序

I need to list the attached event handlers to window unload event

我需要列出附加的事件处理程序到窗口卸载事件

You'll find the handlers for the window unload event listed on the body element, so navigate there in the DOM Inspector to see them:

您将找到body元素上列出的窗口卸载事件的处理程序,因此在DOM Inspector中导航以查看它们:

在IE中查看DOM级别2事件处理程序

#1


2  

Yes, you can easily see DOM2 handlers:

是的,您可以轻松查看DOM2处理程序:

  • Right-click the element with the event handler and choose Inspect Element

    右键单击具有事件处理程序的元素,然后选择“检查元素”

  • That should trigger the DOM Explorer tab; if not, do so

    这应该触发DOM Explorer选项卡;如果没有,那就这样做

  • Pick the Events tab on the right-hand side

    选择右侧的“事件”选项卡

It lists the event handlers attached to the element, including DOM2 ones.

它列出了附加到元素的事件处理程序,包括DOM2。

For instance, using this fiddle:

例如,使用这个小提琴:

<div id="target">
I have a DOM2 event handler.
</div>

function thisIsADOM2Handler() {
    this.style.color = "green";
}
document.getElementById("target").addEventListener("click", thisIsADOM2Handler, false);

I followed the steps above to see this:

我按照上面的步骤看到了这个:

在IE中查看DOM级别2事件处理程序

I need to list the attached event handlers to window unload event

我需要列出附加的事件处理程序到窗口卸载事件

You'll find the handlers for the window unload event listed on the body element, so navigate there in the DOM Inspector to see them:

您将找到body元素上列出的窗口卸载事件的处理程序,因此在DOM Inspector中导航以查看它们:

在IE中查看DOM级别2事件处理程序