How to list available events in an element in IE8?

3

I'm doing a shim / polyfill to work with CustomEvents to IE8, but I'm having a problem detecting when the event is not standard.

In IE8 each element may have a different list of available events, there is no possibility of executing a attachEvent other than an available event by default on the element.

In the IE8 debugger, when we apply a watch in the context of the element ( this in an element method) it shows a list object [Events] which contains the available events even.

The problem is that I can not access this property other than through the debugger.

How can I access this list property, or is there any other way to find out which events are available in the context of the element?

    
asked by anonymous 14.02.2014 / 03:44

1 answer

3

I have found that IE8 actually only lists the properties it recognizes as events, but these are all properties of the object's own context.

Then to list the events available to do so:

var eventos = [];
for (var prop in this) if (prop.indexOf('on' === 0) {
    eventos.push(prop);
}

In the above case this (context) is an HTML element because this code would be running inside a method of this element. But it also works by passing the element reference instead of the context ( this ).

To find out if the event belongs to the element to do so:

if ('onload' in this) {
    /* onload pertence a este elemento do contexto */
}
    
14.02.2014 / 04:14