inutan
inutan

Reputation: 10888

Debugging javascript 'unspecified error' in IE7

I have my application in Visual Studio 2008, .net 3.5 running under IE7.
It's running fine in Firefox, however getting 'unspecified error' in IE7 -

Error - 
Line: 28
Char: 56
Error: Unspecified error.
Code:0
URL: ***.aspx

As there are around 15 .js file that are being loaded on this page, I am not able to have any information even to locate the error code.

Could anyone please guide me the way to debug this error.

Thank you!

Upvotes: 1

Views: 1828

Answers (2)

Nate
Nate

Reputation: 13252

Unspecified error. can mean a lot of things. Here are some tips for identifying the issue.

Run a JavaScirpt Linter

You can paste your code into JSLint.com, JSHint.com, install JSHint or a verity of other JavaScript Linters.

JSHint is probably your best bet in this case because it has some options that make it lint more strictly and for older versions of the spec. There is a list of JSHint options that you can look at but the one that matters here is es3.

Use this option if you need your program to be executable in older browsers—such as Internet Explorer 6/7/8/9

Add this to the top of your JS file:

/* jslint es3: true */

Or add a .jshintrc file to the directory or a directory above your JS files and put this in it:

{
  "es3": true
}

Then run JSHint:

jshint myfile.js

Some Internet Explorer 7 issues

new keyword

I noticed that the Unspecified error I was getting was actually me using the new keyword as an object property like this:

var MyCustomClass = function() { /* ... */ }
MyCustomClass.new = function() {
/*            ^ Unspecified error here */
  var mycustomclass = new MyCustomClass();
  // Do extra stuff with mycustomclass
  return mycustomclass;
}

Above, I was using new as a helper method to do some extra stuff when the class is created. This is probably not the ideal solution and thinking about it now I could probably do that stuff in the class constructor, but my issue was my use of the new keyword as an object property. Apparently IE7 considers this a script-stopping error while newer browsers do not (I don't know about IE8).

Accessing offsetParent

When reading the offsetParent of an element, IE7 gives the wonderful Unspecified error. There is a StackOverflow question about this. You can fix this by wrapping your code in a try catch.

var op;
try {
  op = element.offsetParent
}
catch(unused) {}

Upvotes: 0

enloz
enloz

Reputation: 5844

IE7 debugger is worth nothing.

But there is a nice tool Internet Explorer Developer Toolbar and Web Development Helper

And you should read stackoverflow / Debugging JavaScript in IE7 too.

Upvotes: 2

Related Questions