views:

24

answers:

2

Hello there people!

I'm currently working on a very poor developed system, and I have to make some bug fixes before this product is released in beta stage.

The site is built with lots of javascript, and I'm not very familiar with it. The question is - is there a way to read how my function was executed?

Like.. Function was called by onClick, or onMouseOver or something like that.

Thanks in advance!

A: 

Firefox has a tool called "Firebug" which lets you debug the JavaScript.

If you select the "Script" tab in Firebug, stick a breakpoint inside the function and then select the "Stack" tab in the right hand panel, you should see the information you need.

If you don't have Firebug, get it here:

https://addons.mozilla.org/en-US/firefox/addon/1843/

Sohnee
Well... Yes, Firebug can tell lots of different information. But I want to achieve this with Javascript itself, because I want my function to execute differently if called by onClick or otherwise.
Tom
+1  A: 

If you can, pass the event object to these functions, ie:

<div onclick="ev(event||window.event)" onmouseover="ev(event||window.event)">
  The div
</div>
<script>
    function ev(e){
        // e.type will have the value 'mouseover' or 'click' based on what you do
    }
</script>
Mic
Not sure if this will work in my case, but, I tested it, and works like I imagined. Accepted and thanks!
Tom