views:

740

answers:

4

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!

+1  A: 

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.

A: 

For IE, download the Microsoft Script Debugger

digitalsanctum
The problem is that I don't get this warning/error when I enable the Script debug(IE + Other), so I cannot put a break point either.
royalGhost
+1  A: 

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.

Shog9
+2  A: 

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.

nickf