开发者

How to find .js file where certain js function is declared (from Chrome)?

For example if I run on some page in Chrome with following code:

<div onclick="someFunction('test')"></div>

I would like to know which js file contains "someFunction". Is it possible and how? (I suppose it could be done with d开发者_JAVA技巧ebugging but don't know how)


In Firefox with Web Developer add-on, Information/View Javascript/Expand All, search for "someFunction".

There are of course, a lot of other ways to do this too, but this add-on puts all JS from the page into one browser which makes it simple to search for anything page-wide.


what I do is: [ Assuming you have access to the source code ]

grep -r "function someFunction" . 

where . is directory where to begin recursive search for the pattern. It will show you all files which contains pattern "function someFunction".

By the way, if you have a lot of hits but you want to search in the directory which generates them, you can discard results that contains:

grep -r "function someFunction" | grep -v "withouth this text"

hope that helps! on windows maybe you can use this with cygwin ?

This of course will not work if someFunction is hosted on external host...


Try to save page in file system (menu -> save page as -> web bage completely) and find you function in files by text searcher.


Write the function name in google console without parenthesis e.g- for function submit(a,b) - i want to know where is the submit function.

just write submit in the console.The output will be definition of the function. Click on the output, you will be redirected to the function.You can see the file name at the top of the developer tools in source tab.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜