Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to find actual location of line/char in Internet Explorer Script errors?

I'm receiving a script error in IE:

Line: 59 Char: 71 Error: Expected identifier, string, or number Code: 0

Line 59, character 71 don't seem to actually correspond to my code. It doesn't even say what file, but I've looked at my main javascript file, viewing the page source, etc.

This has happened to me before and I've looked around until I finally find an error with the code -- usually a comma -- but I would really like to get some use out of these line/char numbers. I read once that it's a reference to the internal version of the page that IE reads from.

Does anyone have information on how to find out what these numbers actually mean and see the line of code that's causing the problem?

Appreciate any help!

like image 551
croixhaug Avatar asked Oct 01 '09 21:10

croixhaug


People also ask

How do I view JavaScript errors in IE 11?

Load you website, then press f12 to display the Developer tool.. any errors that have occurred will be listed in the Developer tool console. Display the Developer tool, selecting the Debug tab, select an option on the dropdown on that tab, 'Break on all exceptions' or 'Break on unhandled exceptions'.

Why do I keep getting a script error message on my computer?

A: Script error messages tend to appear when one's browser is out of date. What happens is the website you are visiting contains a version of JavaScript (the programming language that allows for animation and interactivity on websites) that is newer than what is installed on your browser.


2 Answers

I've found IE Line # / Char #'s to be useless or more hassle then it's worth.

If you're including multiple javascript files and all it gives you is a line # and char # it's alot of work to concatenate all the scripts together to figure it out where the error is.

If I can find the error in firefox using firebug then that's the easiest way. If it's an IE only problem what I do is enable script debugging in Internet Options,

  1. Go to Tools->Internet Options…->Advanced->Disable Script Debugging (Internet Explorer)

  2. Go to Tools->Internet Options…->Advanced->Disable Script Debugging (Other)

    then attach Visual Studio Debugger when an error occurs.

If you're using IE 8, install the developer toolbar because it has a built in debugger.

If you are really keen on not using a debugger and just viewing the source and getting the line # you can try View -> Original Source in the IE Developper toolbar.

In your case you gotta watch out for trailing comma's in object literals

var obj = { 
a: 1, 
b: 2,
}

Or naming a variable with a reserved keyword like "class", that has burned me many times. Here is a list of reserved keywords

like image 130
Ryu Avatar answered Nov 15 '22 15:11

Ryu


I would recommend trying out the same page in IE8, if you haven't done so already. If the error doesn't happen, try switching IE8 to Compatibility View.

If you do get the error to occur, then the built-in Developer Tools are very good at finding exactly where the problems in the Javascript occur.

like image 39
Coxy Avatar answered Nov 15 '22 16:11

Coxy