W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2012

Re: [whatwg] Detecting eventListeners

From: Xavier Ho <contact@xavierho.com>
Date: Fri, 25 May 2012 12:45:35 +1000
Message-ID: <CALWePYy+9JRYR4rH9OPV-B3pvYyG665shmdqh0hXXihM9GH7XQ@mail.gmail.com>
To: Jason Edward 今井 Parrott <parrott.jason@gmail.com>
Cc: whatwg@whatwg.org
Hello Jason,

On 25 May 2012 12:33, Jason Edward 今井 Parrott <parrott.jason@gmail.com>wrote:

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

That's not what I'm asking.  I'm asking to check if an event listener
exists, not to remove it.


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

We could add 1000 lines of code that overrides every single
addEventListener on any arbitrary HTMLNode.  That's a great solution.

Tongue-in-cheekly yours,
Xav




>
>
> On Fri, May 25, 2012 at 10:34 AM, Xavier Ho <contact@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
>>
>
>
Received on Friday, 25 May 2012 02:46:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:08 GMT