user2294256
user2294256

Reputation: 1049

How to determine which JavaScript file opens a popup window

when I click a button on a site, one popup window shows, how could I check this popup windows calls which js file and the codes in that file? I right click the site and chose view page source, in the <head>...</head> section, there are many js files, I can not tell which is the one for this popup window.

Upvotes: 2

Views: 1196

Answers (3)

Arman Bimatov
Arman Bimatov

Reputation: 1829

Check out Google Chrome Developer Tools (F12 key).

In the Elements section find the button that causes the popup, then in the Resources tab, click on each js file on the left and search on the right for the reference to your button.

As a reference you should consider both the id of the element and the class.

You should finally find something like a $("#yourbutton").click. Or it might even be in the properties of the button, like <button onclick="someFunction"/>. Then just search for that function.

It's really not that bad with the browser tools (you can do something like that in Firebug too).

Upvotes: 1

Jeremy J Starcher
Jeremy J Starcher

Reputation: 23863

Another option is to use the Profiler under Google Chrome.

Open up the debugging tools [F12],

Then make sure Collect CPU profile is selected and hit Start.

Click your button, then turn off profiles.

That will give you a list of every Javascript function executed. Greatly narrows down the list of things to search through.

Upvotes: 1

rink.attendant.6
rink.attendant.6

Reputation: 46218

  1. Save the web page with the option Web Page, complete (this option is available in most if not all major browsers). This will save all of the HTML, CSS, JavaScript, image and other media files embedded in the page. You may delete the images, media, and even CSS.
  2. Start taking out every <script> element one by one, checking each time to see if the button still functions.
  3. If it doesn't, put it back and continue with the other elements until you've narrowed it down to the one or few critical elements.
  4. Start reducing the JavaScript code in the same way, whether it is in an external JS file or internally written in a <script> block. Take out a variable or function one at a time, checking each time to see if it works.

In the end, you will have reduced the code to a minimal test case to see how to reproduce the desired results (i.e. the popup window).

Upvotes: 1

Related Questions