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) {}