aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Is there a listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Is there a listener" Watch "Is there a listener" New topic
Author

Is there a listener

Al Gettier
Greenhorn

Joined: Nov 16, 2005
Posts: 8
For a given DOM node, is there a way to tell if someone has "addEventListener()" a handler to it?

Can I find out when event is being listened for or what function is being called?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can reference the node/element and look at the code.

alert(document.getElementById("test").onclick);

Eric
Al Gettier
Greenhorn

Joined: Nov 16, 2005
Posts: 8
This does not work for me. Here is my code:

document.addEventListener("click", function(e){alert("In My Handler"+e);}, false);
alert("onclick: "+document.onclick);
alert("click: "+document.click);

For both of the alerts I get undefined. This was done in Firefox 1.5
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Can I ask you why you are doing this?

Also you can delete posts by clicking on the edit icon and checking the delete box. So I do not have to do it next time!

Eric
Al Gettier
Greenhorn

Joined: Nov 16, 2005
Posts: 8
Thanks for deleting my errant post.

We are trying to provide a quality control product for people who write AJAX appliations.

So what we would like to do is report back all handlers that have (or may have) been called for an event when it happens.

For example we want to attach a listener for "click" at the <body> level. Then when the click occurs we go up the DOM tree, reporting what levels of the DOM have a "click" listener.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a listener