Capturing all DOM Events

Discussion in 'JavaScript' started by bsnl, Feb 22, 2009.

  1. #1
    Hi, my company has a bunch of web pages on which they want to record every DOM event(mouse movement, clicks etc), these pages were written in past and now with minimal editing I need to add listener to capture these events.
    Can someone provide an easy and effective way to do this (may be addition of eventlistener at Body tag to capture all bubbled up events, but i am not sure if it will work when stopPropagation method is called by some eventlistener in the chain).
    I am looking for a universal listener kind of thing that can be easily integrated with my pages.
    Thanks to every reader of this question
     
    bsnl, Feb 22, 2009 IP
  2. cjburkha

    cjburkha Peon

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What you are asking for is very hard for two reasons:

    1. Mousemove happens so often you cannot catch them all in DB
    2. There are many events and IE and FF handle them different

    Start with this sample, and then look to quirksmode.org
    <html>
    <head>
    <script type="text/javascript">
    function iniHandlers()
    {
    
    document.getElementById('innerDiv').onclick = clicked;
    document.getElementById('mainDiv').onclick = clicked;
    }
    
    function clicked()
    {
    alert(this.id);
    }
    </script>
    </head>
    <body onload="iniHandlers();">
    <div id="mainDiv" style="width: 100%; height: 100%; ">
    <div id="innerDiv" style="width: 100px; height: 100px; border-style: solid">
    </div>
    </div>
    </body>
    </html>
    Code (markup):
     
    cjburkha, Feb 24, 2009 IP