Niyaz
Niyaz

Reputation: 54793

How to handle all the events in a web page

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

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 web page instead of listening to each event separately (without using jQuery)?

Upvotes: 0

Views: 960

Answers (3)

mck89
mck89

Reputation: 19241

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);
      }
  }
}

Upvotes: 1

austin cheney
austin cheney

Reputation:

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.

Upvotes: 2

annakata
annakata

Reputation: 75814

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.

Upvotes: 1

Related Questions