Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
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()?
The simplest solution for a function which is defined in the global scope :
open the console of your browser (F12 in most browsers)
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.
If you can execute boormakrlets in your address-bar, you could do:
javascript:abc.toString()
Or better:
javascript:alert(abc.toString())
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
remember, I am a beginner. So I have been using the alert(variable_here)
function to check and make sure any variables I a changing are doing what they are supposed to while I am coding. For example:
var randomevariable = (2)//set the variable
randomvariable = (randomvariable + 1)
alert(randomvariable)//see how I used the alert function as temporary statement for checking the variable?
Is there a better way to view a variable than document.write and alert?
I would recommend using console.log or the debugger statement:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
https://developer.mozilla.org/en-US/docs/Web/API/Console/log
Debugging using a modern browser also helps:
https://developer.chrome.com/docs/devtools/open/
You can use the web browser's console, typically accessible with Right click > Inspect.
To print anything in the console while the code is running, you can put this in Javascript:
console.log(randomvariable)
This is less disruptive than alert!
If you're working in a browser environment, console.log() is going to give you an easier time than using alert() - using Chrome and most other modern browsers, you can press CTRL+Shift+I to open Chrome Dev Tools to see the chrome console and see the output of console.log() there.
There are some cases when debugging more complex bugs I also like to put variables on the window object - this gives them a global scope and lets me check their value at any given moment.
For example: window.myVar = myVar;
Then, later, when I want to check the value while debugging, you can go into the same chrome dev tools and type window.myVar to see their value.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I know there is a lot of question about this but I check all of them, nothing with the same error (I might have missed one or two post)..
So, I get this jsFiddle to know how to open a facebook share window inside the current window in order to have my own share button.
But this fiddle is not working on my local.
I didn't change the code first to test so it's not because I change something.
Chrome's console throw me this error pointed on the window.open():
Uncaught TypeError: boolean is not a function
What I missed ?
Thank you in advance
It works, the problem don't come from there,
Did you overwrited the function "open" in your code? like a global variable that you have set as a boolean ?
just ctlr + F your scripts to find a "open" or "var open" ^^
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am new to JS and I am trying to figure out the most efficient way to perform this task.
Stack Exchange keeps a list of its member-sites at https://stackexchange.com/sites
What is the most efficient way to extract this data into a data-structure, like an array or dictionary in JavaScript?
It seems like all the stackexchange sites are built with the same framework. If you check in your console, you can see that a javascript object StackExchange is defined on any stackexchange site.
If you just want to scrape that link in your question, you can go there in your browser, and type this in your console: $('.gv-item-collapsed-wrapper h2').text()
That page already has jQuery loaded, which you can use to search through elements on the page. That code snippet will show you all the site titles in a string.
Better yet (but a little more complex)
var arr = [];
$('.gv-item-collapsed-wrapper h2').each(function(){arr.push($(this).text())});
I just tested a small portion of the sites, and this seems to work:
window["StackExchange"] !== undefined
If you look at the source of any page, there is always something like this:
StackExchange.ready(function () {
So basically you're checking to see if that class, StackExchange exists, and if it does, most likely (I'm sure in the masses of the internet, somebody is borrowing/stealing the code or using the same name) a StackExchange site.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to write javascript code that affects the breakpoints in debugging mode in Chrome console.
something like:
function someJavascriptCode() {
console.log('will stop here for debugging');
debugger; // stop!
chrome.debugger.stepOver(); // just like clicking F10 in the console when in a breakpoint
console.log('This line just happened because of the previous line');
}
Any ideas?
Nothing like that is implemented, nor is it likely to be in that manner because it doesn't make any sense to have functions to control the debugger in runtime code. It could possibly be done with some kind of directive, but I doubt anything like that exists and I can't really think of any genuine use cases.
If you're looking to do this externally, you might want to take a look at the remote debugging protocol or writing a debugger extension.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am writing up some code in Javascript/JQuery that involves some confusing DOM operations, or at least they are to me because I'm relatively inexperienced.
I try to help myself by doing a couple of console.log()s, but the thing is if you just log a DOM element you get useless information, mostly it's object Object.
I was wondering what the most usefull generic attributes of a HTML element are so that I could easily follow what the script is doing?
I was wondering what the most usefull generic attributes of a HTML element are so that I could easily follow what the script is doing?
Don't use logging for debugging. Use a debugger for debugging. Even IE (8 and up) has a debugger built in. If you want to know what the code is doing, there's nothing that substitutes for stepping through the code in the debugger and examining your various variables and such as you go.
But answering your specific question, I'd say I'd want to see the DOM element's tagName, className (e.g, class[es]), and id (if any).
I would use chrome when inspecting the console log, the objects actually come through so you can expand and see all of their properties. Keep in mind some of the older browsers, IE8 or 7, do not support console.log and it will throw a javascript error.