views:

238

answers:

2

I'm wondering why when I call: eval("myFunc(1,2,3)") in the Firebug console on a rendered page, the function executes properly, but when I call the same eval within by javascript within then page, I get a " is not defined" error that pops up in the Firebug console. Part of my problem is that I don't have control over the incoming HTML/JS and I can't seem to find where the function is defined. So I guess my questions are, why am I getting that error and how can I find where the function I'm trying to call is defined? If I pull up the page source, I can see calls to the function but I don't see where it is defined.

+1  A: 

The function is probably defined in an external file. In firebug, if you just type out myFunc (without paranthesis) you should be able to get a clickable link to the source.

The reason it's not working in your eval-script, is probably that it's being executed before the function is defined. Try defering it by, say, putting it in a page load or domready event listener.

Henrik Adolfsson
+1  A: 

If you view the source you should be able to see any JS in the source code and any attached js files too - you should be able to download them and open them in your editor then do a find.

matpol
So I did this...very helpful and now I can see where it is defined. It is indeed an externally sources (src=) javascript file. My question now...I notice it seems like it is passing some sort of parameter when it is loading. It looks like: <script src="/theJSLib.js?t=8" type="text/javascript"></script>What is the "?t=8" Is it passing a parameter?
GregH
perhaps - if it is using it in the script look for the var t - might just be an anti caching thing.
matpol