Attachevent Or Addeventlistener - Stored Where?
Solution 1:
From quirksmode:
One problem of the current implementation of W3C’s event registration model is that you can’t find out if any event handlers are already registered to an element. In the traditional model you could do:
alert(element.onclick)
and you see the function that’s registered to it, or undefined if nothing is registered. Only in its very recent DOM Level 3 Events W3C adds an eventListenerList to store a list of event handlers that are currently registered on an element. This functionality is not yet supported by any browser, it’s too new. However, the problem has been addressed.
Solution 2:
If you can get code installed at the beginning of the page, you can record all subsequent listeners in your own data structure with this kind of hook: Why does Google +1 record my mouse movements?.
I know of no way to access the existing listeners.
Solution 3:
// Introduced in DOM Level 2:
interface EventTarget {
void addEventListener(in DOMString type,
in EventListener listener,
in boolean useCapture);
void removeEventListener(in DOMString type,
in EventListener listener,
in boolean useCapture);
boolean dispatchEvent(in Event evt)
raises(EventException);
// Introduced in DOM Level 3:
readonly attribute EventListenerList eventListeners;
};
So el.eventListeners
contains all event listeners attached to el
using el.addEventListener
.
You would need to use a shim to deal with browser support. Currently Chrome 12 and Firefox 5 do not support this
Post a Comment for "Attachevent Or Addeventlistener - Stored Where?"