Javascript has many different performances in IE and FireFox. The following lists some common differences. In-depth understanding of these differences can help Web developers and designers avoid common mistakes and improve development efficiency.
BKJIA recommended reading: Javascript solves Common Browser compatibility problems
1.doc ument. formName. item ("itemName ")
Description: You can use document. formName. item ("itemName") or document. formName. elements ["elementName"]; In Firefox, only document. formName. elements ["elementName"].
Solution: Use document. formName. elements ["elementName"].
2. Collection class Object Problems
Note: in IE, you can use () or [] to obtain collection class objects. In Firefox, you can only use [] to obtain collection class objects.
Solution: use [] to retrieve collection class objects.
3. Custom Attributes
Note: in IE, you can use the method to obtain general attributes to obtain custom attributes, or use getAttribute () to obtain Custom Attributes. In Firefox, you can only use getAttribute () obtain custom attributes.
Solution: getAttribute () is used to obtain custom attributes.
4. eval ("idName") Problems
Note: in IE, you can use eval ("idName") or getElementById ("idName") to obtain the HTML object whose id is idName. In Firefox, you can only use getElementById ("idName ") to obtain the HTML object whose id is idName ..
Solution: getElementById ("idName") is used to retrieve the HTML object whose id is idName.
5. The variable name is the same as the ID of an HTML object.
Note: In IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document; in Firefox, it cannot. in Firefox, you can use the same variable name as the HTML Object ID; in IE, you cannot.
Solution: Use document. getElementById ("idName") replaces document. idName. we recommend that you do not use variable names with the same HTML Object ID to reduce errors. When declaring variables, add var to avoid ambiguity.
7. input. type attribute Problems
Description: The input. type attribute in IE is read-only, but the input. type attribute in Firefox is read/write.
9. event. x and event. y
Note: In IE, the even object has the x and y attributes, but does not have the pageX and pageY attributes. In Firefox, the even object has the pageX and pageY attributes, but does not have the x and y attributes.
Solution: Use mX (mX = event. x? Event. x: event. pageX;) to replace event. x in IE or event. pageX in Firefox.
10. event. srcElement Problems
Note: In IE, the event object has the srcElement attribute, but does not have the target attribute. In Firefox, the event object has the target attribute, but does not have the srcElement attribute.
Solution: Use obj (obj = event. srcElement? Event. srcElement: event.targettoken used to replace event.tar get under firefox.
13. frame Problems
The following frame is used as an example:
- <frame src="xxx.html" id="frameId" name="frameName" />
-
(1) access the frame object:
IE: Use window. frameId or window. frameName to access this frame object.
Firefox: only window. frameName can be used to access this frame object.
In addition, both ieand firefoxcan access this frame object by using the upload metadata Doc ument. getElementById ("frameId.
(2) Switch frame content:
In both ieand firefox, you can use Upload upload Doc ument. getElementById ("testFrame"). src = "xxx.html" or window. frameName. location = "xxx.html" to switch the frame content. If you want to return parameters in the frame to the parent window, you can use parent in frme to access the parent window. For example, parent.doc ument. form1.filename. value = "Aqing ".