0

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 Answers2

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.

Community
  • 1
  • 1
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • I'd better formulate as *Learn how to use a debugger*. – VisioN Dec 18 '13 at 14:35
  • 5
    @VisioN: Then perhaps you could help in teaching this valuable skill, instead of just being a dick. What are you here for, again? – Lightness Races in Orbit Dec 18 '13 at 14:36
  • 2
    @LightnessRacesinOrbit That was rude. – VisioN Dec 18 '13 at 14:38
  • 2
    @VisioN Both comments are a little excessive, as often happens in internet interaction :) <-- here's a smiley to be sure I hurt nobody – Denys Séguret Dec 18 '13 at 14:38
  • 1
    @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? – VisioN Dec 18 '13 at 14:50
  • I was trying to find an function source "changebackground()" on website http://www.noisli.com/ but it returns an error –  Dec 18 '13 at 14:53
  • @baibavkumar Well, the function doesn't exist, maybe because there's an error before it get defined, or maybe because it was removed. – Denys Séguret Dec 18 '13 at 14:58
  • I was trying to get the code of how background color changes with time can you please help me out of it.. –  Dec 18 '13 at 15:07
  • @LightnessRacesinOrbit Excuse me but "you seemed to be suggesting ..." plus all mentioned doesn't entitle you to offend me. I am not a little boy, I know what I say, where and when. I know the limits you are talking about and never attempt to outrage anyone. If you feel yourself inconsistent with someone's opinion, examine the situation first before flaming. – VisioN Dec 18 '13 at 15:25
  • 4
    The holidays bring out the best in people... – rlemon Dec 18 '13 at 15:31
  • Merry christmas, @rlemon! This is pretty much the best in me ;) – Lightness Races in Orbit Dec 18 '13 at 15:38
  • @VisioN: That is my exact advice to you, with regards to how you approach contributing to a question on Stack Overflow. Happy holidays. – Lightness Races in Orbit Dec 18 '13 at 15:39
1

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

javascript:abc.toString()

Or better:

javascript:alert(abc.toString())
Nippey
  • 4,708
  • 36
  • 44