www.webdeveloper.com
Results 1 to 3 of 3

Thread: Find out what function has been invoked

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Exclamation Find out what function has been invoked

    Quick question. (I tried to use firebug but have no idea how to do it correctly)

    I have got some button at page. After click it triggers some function. How to exactly find out what is the name of this function and which library (file) loading it.

    need this to investigate some bug in 3rd party library


    regards
    Piotr Mąsior

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    I guess that event (onclick) was added dynamically...

    It's quite an intricate job. To find which function is triggered onclick, you may do something like that: Make sure your button has an id, say id="myButton". It is not necessary, could be any other DOM way to refer that element, but for the following code (which is a basic example), you need that.

    Code:
    <script type="text/javascript">
    document.onclick=checktarget
    }
    function checktarget(e){
    var target = (e && e.target) || (event && event.srcElement);
    if(target.id!='myButton'){return}
    for(a in target){
    if(a.match(/click/)){alert(target[a]);break}
    }
    }
    </script>
    The base idea of the code is to find which element (target in my code) on the document was clicked, and if it is that button, to circle trough all his properties to find the event attached called onclick (match(/click/) in my code), therefor to alert the value of that event - target[a] in my code -which value is exactly the function you are looking for. Of course, if you are looking for another event, you should modify the code accordingly.

    But there is no way to find using a code where that function is. For that, I recommended you to use Firebug addon for FireFox as browser (use the Firebug's Search box)
    Last edited by Kor; 12-22-2010 at 09:09 AM.

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    thank you, for your reply - good stuff


    regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles