-1

Sometimes it occurs that I like a feature on an page and want to read its javascript, but it is an difficult task to manually find where the function is especially when the webpages more than one js files.

Is there a way I can get/copy the only required js file by its name which I can easily get by inspecting page. examole:

<div id='abc()'></div>

Now how to fine the source of function div()?

2
  • 4
    Am I the only one who found that function abc was called from the id attribute of <div> tag? Commented Dec 18, 2013 at 14:37
  • In fact it's not a function call at all, just a strange id... Commented Dec 18, 2013 at 14:40

2 Answers 2

4

The simplest solution for a function which is defined in the global scope :

  1. open the console of your browser (F12 in most browsers)
  2. type the name of the function

For example type klass in the console on this page.

In the general case, you really need to learn to use the console, including the debugger.


Regarding your practical question : what changes the background of the http://www.noisli.com/ page :

  • it's not the changebackground function : this function doesn't exist
  • it's in the first line of jplayer.js

But the way I found it is too hacky, I hacked the Math.random function by typing this in the console :

Math.random = function(){ debugger; return Math.random() }

so that I would enter in debug and see the call stack...

I hope somebody can propose a clean way.

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

12 Comments

@VisioN: Then perhaps you could help in teaching this valuable skill, instead of just being a dick. What are you here for, again?
@LightnessRacesinOrbit That was rude.
@VisioN Both comments are a little excessive, as often happens in internet interaction :) <-- here's a smiley to be sure I hurt nobody
@LightnessRacesinOrbit I was not attempting to help the OP in this question. My comment was to the dystroy's answer that to my mind can be rewritten shortly as Learn how to use a debugger. Am I wrong? What are you nervous for? You haven't tried to help the OP either, should I also call you a dick and continue saying roughnesses?
The holidays bring out the best in people...
|
1

If you can execute boormakrlets in your address-bar, you could do:

javascript:abc.toString()

Or better:

javascript:alert(abc.toString())

6 Comments

UM, why would you do that in the address bar and not in the console? It is not 1999 anymore. :)
You're right, bum I'm too lazy to open the console :p
@Nippey that's shameful.
Shame on me :) But HEY it's backwards compatible. Maybe I'm still surfing with IE5.. ^^
Nothing wrong with this approach. Not every debugging technique requires a huge "console" or developer tools plug-in.
|