Image by Friedcell via Flickr
As nowadays less and less development goes on in Internet Explorer and the versions that are currently available and widely used have some quirks — to be fair they are by the book and others aren’t — I’m starting this post to have a list of stuff that you need to keep in mind if you don’t want problems when testing in IE.
-
Trailing comma in object literals
This is very common in multiline object definitions.
someObject = {a:17,b:19,};
looks wrong but when you have a newline after everything it’s hard to find. Firefox lets it be, IE breaks silently. This one is easy to catch with JSLint. -
String is not an array
Even though many languages treat it this way. Using
str[i].charCodeAt()
breaks whilestr.charCodeAt(i)
doesn’t. -
Element ownership matters.
This means that you have to take care when creating elements and attaching them to different documents. If you’re using jQuery beware –
jQuery(someElement).append(someHtml);
is ok since it will check what the owner document is butjQuery(someHtml).appendTo(someElement);
might break if execution and someElement are in different documents. You can usejQuery(someHtml, someElement.ownerDocument).appendTo(someElement);
though.
What I do before testing in any browser other than Firefox (Opera is sometimes even stricter) is to check with JSLint how damaged the code is. It will catch all the weirdly written code that might break a browser. And it catches that trailing comma I mentioned.
I’m quite sure the list should be longer but these are the things I encountered in the last few days. When I find more I’ll add them to the list. If you know any that are not on the list add a comment.