Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there any way to know the handlers registered to an event?

10 views
Skip to first unread message

WenDong Zhang

unread,
Mar 28, 2009, 2:30:06 AM3/28/09
to dev-...@lists.mozilla.org
such as:

function foo(){}
function bar(){}

ele.addEventListener('click', foo, false);
ele.addEventListener('click', bar, false);

// the method to list the handlers registered to ele.onclick
foo, bar.

thanks.

--
Best Regards!
Wen Dong

Jonas Sicking

unread,
Mar 30, 2009, 10:04:02 PM3/30/09
to
WenDong Zhang wrote:
> such as:
>
> function foo(){}
> function bar(){}
>
> ele.addEventListener('click', foo, false);
> ele.addEventListener('click', bar, false);
>
> // the method to list the handlers registered to ele.onclick
> foo, bar.

From a web page there is no way no.

You could do something like:

Node.prototype.myAddEventListener(event, handler, capture) {
handlerArray = this.getUserData('handlers');
if (!handlerArray) {
handlerArray = [];
this.setUserData('handlers', handlerArray, null);
}
handlerArray.push(handler);
this.addEventListener(event, handler, capture);
}

Then you can simply call node.getUserData('handlers') to get a list of
all handlers that you've registered. And replace all calls to
addEventListener with myAddEventListener.

/ Jonas

0 new messages