Summary of differences between JavaScript in IE and Firefox browser
There are some differences between JavaScript in IE and in Firefox, and the following summarizes these differences and the solution:
An issue with the ID of the 1.HTML object as the object name
The ID of the Ie:html object can be used directly as a subordinate object variable name for document
Firefox: Not supported
WORKAROUND: Use document.getElementById instead of document.all
2. If the control has only name, no ID, when using getElementById:
IE: objects can be found
Firefox: Return null
Workaround: All controls must have the ID property set
3.Evel:
IE: Support, use eval (idname) to get an HTML object with ID idname
Firefox: Not supported
Workaround: Use getElementById (idname) instead of eval (idname) uniformly.
4.Event:
IE: window.event with global objects
Firefox:event can only be used in the field where the event occurred, passing in the event object when the function is called
Workaround: Use the browser type before using to judge, each use each.
5. Object name in dollar sign ' $ ' instead use underscore ' _ '
6. Collection Class object issues
IE: You can use () or [] to get the collection class object
Firefox: Use only [] to get collection class objects
There are many existing code that cannot be run under Firefox
WORKAROUND: Use [] uniformly to get the collection class object. Document.form.item ("ItemName") Change to Document.form.elements["ElementName"]
7. The variable name has the same problem as an HTML object ID
IE: Cannot use the same variable name as the HTML object ID
Firefox: You can use
WORKAROUND: When declaring variables, add var to avoid ambiguity, so that in IE can run normally. In addition, it is best not to take the same variable name as the HTML object ID to reduce the error.
8.Event positioning problems
IE: Support Event.x and EVENT.Y
Firefox: Support Event.pagex and Event.pagey
Workaround, use Event.clientx and event.clienty uniformly, but in Firefox there are subtle differences between Event.clientx and Event.pagex (when the entire page has scroll bars), but most of the time it is equivalent. If you want to do exactly the same, you can determine the browser type after the corresponding use.
9. Problems with parent nodes
Ie:parentelement Parentelement.children
Firefox:parentnode Parentnode.childnodes
ChildNodes the meaning of the subscript is different in IE and Firefox, Firefox uses the DOM specification, ChildNodes will insert a blank text node. It is generally possible to avoid this problem by Node.getelementsbytagname ().
When nodes in HTML are missing, IE and Firefox interpret ParentNode differently. For example:
<form>
<table>
<input/>
</table>
</form>
The value of IE:input.parentNode is a null node
The value of Firefox:input.parentNode is a form
Workaround: The node in Firefox does not have a Removenode method and must use the following method Node.parentNode.removeChild (node)
10.const problem
IE: const keyword is not supported.
such as const CONSTVAR = 32; This is a syntax error in IE
Firefox: Support
Workaround: Do not use const, instead of Var.
11.body objects
IE: Only after the body tag has been fully read
Firefox: Exists before the body tag is fully read into the browser
12. Custom Attribute Issues
IE: You can get custom properties by using methods that get general properties, or you can use GetAttribute () to derive a custom attribute
Firefox: Only use GetAttribute () to get a custom attribute.
Workaround: Unify by getattribute () get a custom attribute
13.event.srcelement problems
IE:even.srcElement
Firefox:even.target
Workaround: Use to determine the browser type, each with each.
14. Modal and non-modal windows
IE: Supports modal and non-modal windows
Firefox: Not supported
WORKAROUND: Open a new window directly using window.open (pageurl,name,parameters). If you need to pass parameters from a child window back to the parent window, you can use Window.opener in the child window to access the parent window.
15.innerText
Ie:innertext
Firefox:textcontent
16. Statements similar to Obj.style.height = Imgobj.height
IE: Valid
Firefox: Invalid
Workaround: Unify the use of Obj.style.height = Imgobj.height + ' px ';
IE && Internet