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

前端 未结 4 1583
难免孤独
难免孤独 2021-02-19 16:41

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 corres

相关标签:
4条回答
  • Why, use IE7 or IE8 with the web developer tools on. And when you have a JS bug it will ask you if you want to debug this, you will say "yes, I want" and it will open a nice debugger, exactly on the problematic line.
    Sadly, I am on Linux, and cant give you a print screen to show you how to turn this on.

    0 讨论(0)
  • 2021-02-19 16:51

    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.

    0 讨论(0)
  • 2021-02-19 16:57

    Browsers differ in their determination of the line number and thus do not reliably report the correct line number that an error occurred at in relation to the source code. Internet Explorer, for instance, reports the line number in relation to the browser's own internal rendering of the document source, which may or may not match the source file. Firefox reports the location of the error more reliably, reporting the script file that an error occurred in where applicable.

    Line numbers can help you pinpoint the general place in the script where things went awry. You can copy the document source and paste it into a text editor that provides line numbering, such as Textpad. Alternatively, you can set the default HTML Editor on the Programs tab of the Internet Options dialog

    0 讨论(0)
  • 2021-02-19 17:08

    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

    0 讨论(0)
提交回复
热议问题