[whatwg] Detecting eventListeners

Jason Edward 今井 Parrott parrott.jason at gmail.com
Thu May 24 19:33:23 PDT 2012


Personally, I wouldn't want some random library listening and
possibly forcibly removing my event listeners.
Some bad script could do this easily.

However, you could use some prototyping tricks to make this work (hint:
overload Node.prototype.addEventListener)

On Fri, May 25, 2012 at 10:34 AM, Xavier Ho <contact at xavierho.com> wrote:

> Hello,
>
> We're working on a project that requires detection of registered event
> listeners.  Our targets are old-style "onclick" attribute bindings, events
> registered via "addEventListener" (and the IE equivalent), and other custom
> event libraries such as jQuery's.
>
> As far as we can tell, there is no way to determine if an element has an
> eventListener attached to it, created via "addEventListener".  There is a
> sure way to remove an event (via "removeEventListener"), but we want to
> enter some code path if and only if an element has an event registered,
> without altering its eventListener.  This is currently not possible.
>
> Many discussions about this topic has been raised in the past.  This
> Stackoverflow answer has a good summary:
>
> http://stackoverflow.com/questions/7810534/have-any-browsers-implemented-the-dom3-eventlistenerlist
>
> As far as the author could tell, this feature was never implemented due to
> a lack of a use-case.  We have a use-case.  Could someone share some
> thoughts on this?
>
> We are also happy to hear workarounds, if anyone has previously encountered
> this issue and found a way.
>
> Cheers,
> Xav
>



More information about the whatwg mailing list