I don't know anything about javascript but I can't get these two scripts to work together, if anyone could fix my mistakes I'd be very grateful. The scripts are premade from http://www.mf2fm.com/rv/ and function just fine on their own. I've tried to solve the issue myself but I'm unfortunately entirely clueless. I got this error when I tried to test running what I pasted below on a test site; "JavaScript error: Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. on line 48" Line 48 being: document.body.appendChild(stars[j]); if that's any help. The problem seems to be localized to these lines, though they run fine without the second script.
addLoadEvent(clicksplode);
function clicksplode() { if (document.getElementById) {
var i, j;
window.onscroll=set_scroll;
window.onresize=set_width;
document.onclick=eksplode;
set_width();
set_scroll();
for (i=0; i<bangs; i++) for (j=sparks*i; j<sparks+sparks*i; j++) {
stars[j]=createDiv('*', 13);
document.body.appendChild(stars[j]);
}
}}
Well, for one thing, you're copying a script that dates back to 2002 at the very latest. These belong in a museum. I had a whole nostalgic flashback to the 90s loading up that site from your source code.
The error you're getting is that value of stars[j] is not a DOM Node, so appendChild() doesn't know what to do with it.
Since it seems like you're already familiar with the dev console, I'd suggest putting a breakpoint in at that line 48 where you see your error and seeing what is actually being passed to appendChild(). Then you can walk up the stack trace to see where that bad value is coming from. You can also, in chrome dev tools, turn on "pause on exceptions" to automatically stop your code in the debugger when an error is thrown. It's the icon of a pause button in a circle in the upper right of the source tab in the chrome debugger.
Best of luck!
Related
I'm trying to figure out how to develop extensions in chrome and started out with the obvious: adblock plus.
But I noticed something very unsettling: the break points get skipped.
As you can see, I set a break point on the line console.log("Was here 00 " + timeStamp()); but the message was still printed to the screen.
I expect the Javascript interpreter to break on the break points. Obviously it's not happening.
I don't understand this. Can someone please shed some light on this mystery?
Thanks in advance for your kind help.
I'm not totally sure why the breakpoint is not always getting hit, but I suspect it could be some timing issue with the JS engine. It would be interesting to find out for sure. I found a workaround that should help anyway:
Add a debugger statement where you had the logging call. This always gets hit. It's in the code, so there's no issue with timing.
On the line below where you will have the logging call, add a Conditional Breakpoint by right clicking on the line number and selecting "Add conditional breakpoint...". Instead of using an actual condition, just inject the console statement.
For example, console.log("The time is " + new Date());
Now when you load a page, the debugger will break at the debugger statement, and then once you continue execution, the console log will occur.
I am quite new to javascript, I often find the need to walk through JS codes line by line to get better understanding how the code works. But manully setting breakpoints for each line in the 'source' panel of chrome is just too time-consuming, is there a way to do this automatically?
In fact, in some very complicated projects, JS files are littered everywhere in the project folders, it is quite hard and troublesome to locate and open them all in the source panel. So is there a way to let chrome execute JS 1 line at a time, no matter which files the line is in?
Once your code breaks, there's a button beside "resume script execution" called "step over next function call" or F10, which will resume step by step.
The accepted answer is to press F10, which steps over the next function call.
If you truly wish to step a single step at a time however, F9 is simply "step."
I set a breakpoint in a script block of a razor view.
VS2012 attaches to IE but breakpoint has yellow triangle with exclamation mark saying:
The breakpoint will not currently be hit. The code in the document is
not loaded.
Script debugging is enabled in Internet Options of IE.
Have no idea what is wrong.
I faced this problem too. After trying many codes and things take from different posts in Stackoverflow and others websites, they have not solve my problem. When i have take a look for #robert4 solution and go back in my javascript code, i saw one error and fixed it, by doing like that, i have finally solve may problem and can now get a breakpoint in my javascript document. For those who will face this type of problem, i think that the first thing to do it is to verify your js file code by code to see if there is no error before beginning to implement each of others solutions take from differents posts.
When I had similar issue it turned out that an omitted } was the cause
(in one of the JavaScripts of the page, one of the {}s was not closed).
There was no error message on the browser console at all,
just didn't work and I had no clue for half an hour.
When I fixed the missing }, everything began to work as expected.
I'm having a problem where all my javascript errors appear to be coming from dojo.xd.js or a sub-module. I'm using chrome debugger and many dijit features such as dijit.declaration and dojo.parser.
This is a bit annoying as it makes it hard to locate simple errors or slip ups. I'm hoping I can add an option that allows my debugger to show where in my non-dojo code a option would occur.
I'm new to dojo so I might be making a simple mistake.
Example error from what should be a nullpointexception in non-dojo code:
typeError
dojo.Deferred.reject.errback dojo.xd.js:14
Errors that occur inside deferred and async chains are handled by Dojo and that can confuse the error messages a bit.
If you are using the chrome debugger you can tell it to immediately halt the program execution whenever an exception occurs by clicking on the "stop sign" in the "Script" tab until it turns blue.
I think missingno's suggestion is a good one (worth a try - I haven't used the method).
Also, another way I've used to get at the erroring code is:
Set a breakpoint in the dojo code where the error is showing
Use the stack breadcrumb navigator and move backwards into the
code that threw the error
In Firebug, the stack navigator is just above the script listing that shows the breakpoint.
Can any one give me a scripts (HTML/CSS/Javascript) that can reproduce this error on IE 7.0? I am trying to fix this bug in my page where I get this warning but could not exactly found the problem. Line number does not match with the source either.
I thought the better approach would be to create a bug and then work on it incrementally rather than making some wild guess!
As Shog said, that error will occur when you try to call a method on an object which doesn't have that method.
This is most often caused by an object being null when you expect it to, well, not be null.
var myEl = document.getElementById('myElement');
myEl.appendChild(...)
The above example will cause that error if the "#myElement" element doesn't exist.
If it's only happening on IE and not Firefox, chances are it's because you're using a method which IE doesn't support.
The solution? You can try the Script Debugger, but I've never found that to be useful myself. The most reliable, yet painfully slow method is alert() debugging. At strategic points through your code, put in an alert with a unique message. At some point IE will throw an error, so you'll know that the error is somewhere between the last alert which you saw, and the next one which didn't.
function myFunc() {
alert('a');
var myEl = document.getElementById('myElement');
myEl.appendChild(something);
alert('b');
// more code
}
if you ran that and you saw 'a' but not 'b' you know it's in between there somewhere. This is just the sad state of javascript in IE, I'm afraid.
If you make your code follow the jslint.com rules, it will go away.
It will also point you at exactly where the issue is in your code.
I thought the better approach would be
to create a bug and then work on it
incrementally rather than making some
wild guess!
You would be wrong. There are countless scenarios that could produce the error you are seeing. All it means is that you're trying to call an undefined method. For instance:
var blah = {};
blah.methodWhichDoesntExist(); // <-- error
This could be the result of a typo, an undetected failure in some other component, or gamma rays consistently flipping bits in your HTML right after you save. Hard to be any more specific without knowing more about what you're doing.
For IE, download the Microsoft Script Debugger
I just fixed a similar bug by using IE8 and switching it into IE7 mode. You then get a more specific error message telling you which line of which file is failing.
After that set a breakpoint so that the code stops just before the offending line (F12 to get to debugger tools, then choose the JS file you want from the 'scripts' dropdown and click to the left of the line number. Click 'start debugging' to make it use the breakpoints).
As others have pointed out, this error could have many causes, but in my case, I had two IDs on the same page with one capitalised and one not. getElementById() was getting the wrong one. Only IE7 complained.