views:

80

answers:

3

I want to get notified about all the events happening in a webpage.

For each single event I am using something like this:

if(document.addEventListener){
    document.addEventListener('click', function(e) { something(e) } , true);
}else{
    if(document.attachEvent){
     document.attachEvent('onclick', function(e) { something(e) });
    }
}

Is there a simple cross-browser way to get notified about all the events in a webpage instead of listening to each event separately(without using jQuery)?

+1  A: 

All the events? I seriously doubt you do considering event-bubbling and how much noise onmousemove is going to produce.

Stick with discretely whitelist binding to what you actually care about.

annakata
I DO want to get all the events. I will handle those issues by myself.
Niyaz
oh snap!
nickf
+1  A: 

Write a JavaScript application that searches the tags of an HTML document looking for the event attributes. You can then analyze the events any way you want. The output could be written to the current page or be written to another document using the xmlHttpRequest object.

Basically this is the solution. However you do it. Walk the DOM tree, and for each element, add a capture function to each event. Your capture function might want to take the existing handler as input so the existing listeners can be called as well.
Glenn
+1  A: 

Try to call the function passed as argument inside another function that calls all the notify operation

function addEvent(ev,fun){
  var hand=function(e){
     alert(ev+" event"); //Or other notify operations
     fun();
  }
  if(document.addEventListener){
      document.addEventListener(ev, hand, true);
  }else{
      if(document.attachEvent){
          document.attachEvent(ev, hand);
      }
  }
}
mck89