1

This is the following example of what I want to achieve.

<html> <head> <script type="" src="abc.js"></script> <script type="" src="pqr.js"></script> </head> </html> 

Above is one webpage of any domain.It contains 2 javascript path.I want to know wheather this javasripts are actually being used in the webpage OR it is only declaration of javascript files but not calling any of the javascript function in the webpage.

3
  • To input your code parts/Special regions, you just select that part and click on the tool bar button {} to change that part into codes. Commented Dec 5, 2011 at 11:32
  • I don't think this is possible. Commented Dec 5, 2011 at 11:32
  • Fiendishly difficult anyway, at least for some values of "use". Would a script that searched the page for elements matching a condition and then bound an event handler to them count as "used" if there were no elements that matched the condition? What if it bound an event handler to document that checked the target of every click before doing something but nothing on the page would pass the check? Commented Dec 5, 2011 at 11:37

3 Answers 3

2

Both of Javascript files and any other <script> tags you include in the HTML will be included and they will execute what you tell then to execute inside JavaScript

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry Victor.I didn't get your point.And BTW I found Javasript Debugger can do[Not Sure] my work.So I am following that currently.And thanks for the help.
0

You can set a variable on top of each file you include and check whether that variable is set or not in the position you want to know it.

1 Comment

You are right Baszz.But I can do that only when Javascript Source is in My Control.But I am parsing the whole Javscript of different URLs like www.google.com,www.yahoo.com like that.So I cannot edit that JS.And thanks for the help.
0

It depends on if you are in control of those source files or not. If you are, then as already suggested you can simply put an alert or any other kind of flag in each file, and see if they occur on the host page.

If you are not in control of those source files, then you can use a javascript debugger to place breakpoints within each of the files and then reload the page. If the breakpoints get hit, obviously the code is being executed.

6 Comments

very impressive answer rejj.So right now I am following this and get back to you with the feedbacks.And thanks for the help.
And you are right rejj.I am not in a control of source files.I am parsing webpage like www.google.com,www.yahoo.com like that.So can you give me example that what can I do exactly to solve this.I want to execute .js of this webpage which is used by this webpage and not all .js.Thanks in Advance.
And I also look for javascript debugger,but I suppose for this you have the source file locally on your computer,but I am parsing the .js on fly as I mentioned above.So I think this will not help in my case.Please correct me If I am wrong.Thanks...
code for parsing .js and what I used and I am using htmlunit,HtmlPage page = null;WebClient webClient = new WebClient(); webClient.setJavaScriptEnabled(false); webClient.setThrowExceptionOnScriptError(false); page = webClient.getPage(initialUrl); webClient.setJavaScriptEnabled(true); String beforeExecution = page.asXml(); ScriptResult res = page.executeJavaScript(<javascript code>); page = (HtmlPage) res.getNewPage(); if (beforeExecution.equals(page.asXml())) {return false;}
Chrome (as an example) has a pretty good built-in js debugger. Wrench menu -> tools -> developer tools. Go to the scripts tag. There'll be a dropdown listing all js resources on the current page, from here you can pick the script you are interested in. It will show the full source in the window, and you can attach breakpoints at any line by clicking the left hand column.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.