I often suffer from the problem opposite what’s described in this post. That is, I’ve got code in a legacy application designed only for Internet Explorer and I need to get it to work in Firefox.
For example, I recently worked on an app that made heavy use of manually simulating click events, like this:
select.options[0].click();
…which completely broke the application in Firefox. But you wouldn’t find that information in the answers to the other question, because that’s not something you’d ever even attempt if your app first targeted Firefox.
What other things should a developer updating a legacy IE-only application look for when migrating to modern browsers?
Here’s what my previous research uncovered. I’ve seen each of these issues prevent a real-world application from working in Firefox. Please feel free to edit.
The DOM
document.createElementshould take only a tag name, but IE lets youpass arbitrary HTML (with attributes, etc)
document.getElementByIdshould only find elements with the givenid,but IE also returns elements with the given
nameIE creates implicit global variables for DOM elements, but referencing an element this way in Firefox produces the following warning:
IE’s
document.allis a collection of all elements in the document. It is not supported by Firefox.An Element’s text in IE is retrieved using the
innerTextproperty. Firefox calls this propertytextContent.IE allows items in collections to be referenced using function syntax (i.e. with parentheses) instead of the normal array indexing syntax (i.e. with brackets). For example, the following works in IE:
document.forms(0). Firefox does not support this usage.HTMLTableElementrowsandcellsshould refer toHTMLCollections, butIE allows them to be called as functions; Firefox does not.
IE defaults
insertRow‘sindexto -1; Firefox errors if the argument is omitted.The
Node.textproperty is IE-onlyEvents
window.eventis an IE-specific way to access event information; it’s notsupported by Firefox.
Events are attached to Elements in IE using
attachEvent. Firefox usesaddEventListener. Note, also, that the names of events are subtly different in each browser.In IE it’s possible to get the mouse position from non-mouse events, but it’s not in other browsers. In addition, the names of the mouse-coordinate properties are not the same in IE and Firefox.
IE supports a
clickmethod for triggering theonclickevent on HTML elements. No such function exists in Firefox.XML
Firefox splits text nodes into 4096-char blocks; IE does not. This
means that things like
childNodeswill be different in IE and Firefox.Internet Explorer defines a
parseError.errorCodeproperty onXMLDocuments for detecting parser errors. Firefox loads an XML document that contains error information in the document with
documentElement.nodeName=="parsererror".IE ignores whitespace in XML;
firstChildalways returns the firstELEMENT_NODEThe
Node.xmlproperty is IE-onlyFurther reading