How to list available events in an element in IE8?

Asked

Viewed 179 times

3

I’m making a Shim/polyfill to work with CustomEvents for IE8, but I’m having a problem detecting when the event is not standard.

In IE8 each element can have a different list of available events, there is no possibility to execute a attachEvent other than an event available by default in the element.

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

The problem is that I cannot access this property without the debugger.

inserir a descrição da imagem aqui

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

  • 1

    I don’t have IE8 to test now, but you tried Element.prototype.on...? Or with a subtype of Element.

1 answer

3


I discovered, in fact IE8 it only makes a list in the debugger of properties recognized by it as an event, but these are all properties of the object’s own context.

So to list the events available from to do so:

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

In the above case this (the context) is an HTML element because this code is being executed within a method of this element. But it also works by passing the element reference instead of context (this).

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

if ('onload' in this) {
    /* onload pertence a este elemento do contexto */
}
  • Some properties, including some events, are in the prototype.

  • @bfavaretto yes, all are in the prototype, but I really wanted to find the specific element, because depending on the heritage of the prototypes there will be different events for the element. But I appreciate the thought.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.