alert because of one of JavaScript functions - javascript

In our application we have a lot of JavaScript functions and sometimes an "[object Error]" alert comes out from nowhere when using IE7. It happens sometimes. The problem is that I can't figure out which exact function is causing that error. Any hint on how I can debug this?
Thanks.

If you are using IE, then when there is an error in your JavaScript code, there will be an error indicator on the left bottom of the browser window, you can click it to see which line of the JS code goes wrong

base on this article, it is a bug in IE7

Go to the Developer Tools debugger and select Break on Error.

Related

IE 11 showing error when i clicking with jquery function

IE so much confusing me with some errors like this,
SCRIPT1002: Syntax error
File: jquery-2.1.4.min.js, Line:2 Column 2538
The weird thing is , on firefox and chrome running well and no error.
And some button with jquery click function is working.
I'm Using IE 11
Before this i'm using jquery-1.1.13.min.js and when i use jquery 2.0 it still running properly on firefox and chrome
I'm really new with cross browser so any info will helping me very much, thanks :)
For the record I had this error which only showed itself on IE when doing cross-browser testing of a big Javascript code change.
In my case the problem was a function definition which included what would be a default in any other language:
i.e. Function Foo(param1, param2, param3=false)
.. clearly this was a stupid bit of code .. but it took me a while to track down so this might help someone out there. Doesn't show up in Chrome, FF, or even Edge.
Mostly these errors are not problems of jQuery itself. The problem situates in code using jQuery or inserted into jQuery (callbacks or event functionalities). In my case I used $.ajax to load a remote page in a div element. In the page I loaded there where // comment tags in the javascript part. As IE is putting this content on one line, more code that as I wanted was commented and this created the error.
So if in our case us are using $.ajax maybe this can be an issue. Otherwise best thing to do is debugging the code that generates this error and look for code that is not supported by IE (the version you use). Look for functions passed trough to jQuery.

DOM issues in IE

I've developed an application that I had tested in Chrome and Firefox but then upon testing in IE I noticed a few things weren't working quite as they should so I made a couple tweaks and everything seemed to be working as it should.
However, as if by some sort of magic when I was going through another round of testing in IE I started noticing that I was getting a lot of debugging errors that I had previously been getting.
They all seem to be to be DOM related with IE being unable to get the value of properties because the object is either null or undefined.
I was having none of these issues previously and I have absolutely no idea what might have changed to be causing this but does anyone have any experience of this sort of issue and have some suggestions as to how to resolve the issue?
I've had a look through all the different pages and functions I've been working on the last couple hours but can see nothing obvious that might be causing this.
Any help would be very much appreciated.
Thanks!
The latest versions of IE come with a pretty decent script debugger. If you press F12, a developer tools window will pop up. Click on the "Script" tab and start working your problem from there. Its not as robust or efficient as firebug or chrome's developer console, but its better than nothing and more often than not can get you pointed in the right direction when it comes to squishing IE bugs.

Any way to debug JS issue in IE9?

I have a JS script which works in every browser except IE 9. I am not thrown any errors in my IDE or on the page itself but the loading icon just seems to continuously rotate instead of loading the image.
Page can be seen at:
http://www.nacdbenefits.com/jmarston4
I have used tools like Firebug in Firefox before to recognize some issues but this one is stumping me. Anybody had a similar issue before?
you can use IETester

How to debug javascript? [duplicate]

This question already has answers here:
How can I debug my JavaScript code? [closed]
(20 answers)
Closed 6 years ago.
I have some old javascript code from around 2000-2002 which (surprisingly) still works in IE, but doesn't in Firefox, Chrome, Opera etc. I already found out about some quirks, some browsers do some things this way, some another. So there are code snippets on the internet to create some browser plattform independent function that does it.
Now my problem is, to even locate the problems. Right now, there are buttons in the website, when I click them, something happens in IE, but Firefox does just nothing. There isn't even an errormsg. I tried stepping through the javascript Firebug, but at some point in the code, when I do the next debug step, the script just seems to abort, without any error message. It doesn't continue with the next statement. Pretty strange and I have no idea what causes it or how to fix it. :/
So how do I debug javascript so I get error messages telling me what the problem is, for example, what function/variable I'm using isn't defined in firefox or when I use wrong parameters.
Thx & Best regards
Marc
Firebug for firefox is okay. The console for safari and chrome, IMO, is better. In either case, right click the page, hit "inspect element," and click the "console" tab in the pane that pops up. Now you'll see any errors and warnings generated by the page.
If you really want to debug the scripts you can click on the "Scripts" tab and either pause execution immediately or set a break point. Then, you can step through the execution of the script line by line, inspecting the call stack and watch list as you go.
Firefox doesn't popup error messages or put them in the status bar (like IE). You have to open the Error Console to see the errors.
Firefox puts Javascript errors in the Error Console, but also HTML and CSS errors and warnings.
As to what might not work in the code, there are plenty of things that are IE specific and won't work in any other browser. Also there is a big difference between IE in quirks mode and IE in standards compliant mode. Put a proper doctype in the page so that it's rendered in standards compliant mode, which will make IE more like other browsers, and some IE-specific quirks are removed. This might cause your old script to stop working, in which case you know that it's likely that it's some IE-specific feature that causes the problem.
There's FireBug, but it only works for Firefox.
EDIT: Doh, you already mentioned this in your question.

How to reproduce: Script Error, "Object does not support this property or method."

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.

Categories

Resources