Differences between Firefox and IE on JavaScript and CSS)

Source: Internet
Author: User
Differences between Firefox and IE on JavaScript and CSS

 

Keywords: javascript; CSS; Firefox; ie; Difference

1. Document. formname. Item ("itemname ")
Note: in IE, you can use document. formname. Item ("itemname") or document. formname. elements ["elementname"];
In Firefox, only document. formname. elements ["elementname"] can be used.
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.

6. Const Problems
Note: In Firefox, you can use the const keyword or var keyword to define constants. in IE, you can only use the VaR keyword to define constants.
Solution: Use the VaR keyword to define constants.

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.

8. Window. Event Problems
Note: window. the event can only run in IE, but not in Firefox, because the Firefox Event can only be used in the event. firefox must be added to the source for parameter transfer. IE ignores this parameter and uses window. event to read this event.
Solution:
IE & Firefox:
Submitted (event) "/>...
<Script language = "JavaScript">
Function submitted (EVT ){
EVT = EVT? EVT :( window. event? Window. Event: NULL );
}
</SCRIPT>

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 even 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 event.srcelement?firefox. pay attention to the compatibility of event.

11. Window. Location. href
Note: in IE or firefox2.0.x, you can use window. Location or window. Location. href; In firefox1.5.x, you can only use window. location.
Solution: Use window. location to replace window. Location. href.

12. Modal and non-modal window Problems
Note: in IE, you can use showmodaldialog and showmodelessdialog to open modal and non-modal windows; in Firefox, no.
Solution: Use window. Open (pageurl, name, parameters) to open a new window.
If you want to pass the parameters in the Child window back to the parent window, you can use window in the Child Window. opener to access the parent window. for example, VAR parwin = Window. opener; parwin.doc ument. getelementbyid ("aqing "). value = "aqing ";

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. frameid and framename can have the same name.
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 frame content.
If you need to return the parameters in the frame to the parent window (note that it is not opener but parent frame), you can use parent in frme to access the parent window. Example: parent.doc ument. form1.filename. value = "aqing ";

14. Body Problems
The body of Firefox exists before the body tag is fully read by the browser. The body of IE must exist only after the body tag is fully read by the browser.

15. Event delegation Method
IE: Document. Body. onload = inject; // function inject () has been implemented before this
Firefox: Document. Body. onload = inject ();

16. Differences between Firefox and IE parent elements (parentelement)
IE: obj. parentelement
Firefox: obj. parentnode
Solution: because both Firefox and IE support DOM, using obj. parentnode is a good choice.

17. cursor: hand vs cursor: pointer
Firefox does not support hand, But ie supports pointer
Solution: Use Pointer

18. innertext works properly in IE, but innertext does not work in Firefox. textcontent is required.
Solution:
If (navigator. appname. indexof ("Explorer")>-1 ){
Document. getelementbyid ('element'). innertext = "My text ";
} Else {
Document. getelementbyid ('element'). textcontent = "My text ";
}

19. When setting the style of the HTML Tag in Firefox, the values of all positional and font sizes must be followed by PX. This IE is also supported.

20. IE, Firefox, and other browsers have different operations on table labels. in IE, assigning values to innerhtml of table and TR is not allowed. When adding a Tr using JS, the appendchild method does not work.
Solution:
// Append an empty row to the table:
VaR ROW = otable. insertrow (-1 );
VaR cell = Document. createelement ("TD ");
Cell. innerhtml = "";
Cell. classname = "XXXX ";
Row. appendchild (cell );

21. Padding Problems
Padding 5px 4px 3px 1px Firefox cannot be abbreviated,
Must be changed to padding-top: 5px; padding-Right: 4px; padding-bottom: 3px; padding-left: 1px;

22. When the indentation of UL and ol lists is eliminated
Style should be written as: List-style: none; margin: 0px; padding: 0px;
The margin attribute is valid for IE and the padding attribute is valid for Firefox.

23. Transparent CSS
IE: filter: progid: DXImageTransform. Microsoft. Alpha (style = 0, opacity = 60 ).
FF: opacity: 0.6.

24. CSS rounded corners
IE: rounded corners are not supported.
FF:-moz-border-radius: 4px, or-moz-border-radius-topleft: 4px;-moz-border-radius-topright: 4px; -Moz-border-radius-bottomleft: 4px;-moz-border-radius-bottomright: 4px ;.

25. CSS double-line concave and convex border
IE: Border: 2px outset ;.
FF:-moz-border-top-colors: # d4d0c8 white;-moz-border-left-colors: # d4d0c8 white;-moz-border-right-colors: #404040 #808080;-moz-border-bottom-colors: #404040 #808080;

26. operations on the Select Options set
Apart from [], the enumeration element selectname. options. item () is also acceptable, and selectname. options. length, selectname. options. add/Remove can be used in both browsers. Note that the element is assigned after the add operation. Otherwise, the Operation will fail (this is my test ).

27. Differences between XMLHTTP
// MF
If (window. XMLHttpRequest) // MF
{
XMLHTTP = new XMLHttpRequest ()
XMLHTTP.
XMLHTTP. Open ("get", URL, true)
XMLHTTP. Send (null)
}
// IE
Else if (window. activexobject) // code for IE
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ")
If (XMLHTTP)
{
XMLHTTP.
XMLHTTP. Open ("get", URL, true)
XMLHTTP. Send ()
}
}
}

28. Differences between innerhtml
Firefox does not support innerhtml. The solution is as follows:
RNG = Document. createRange ();
El = Document. getelementbyid (elementid );
RNG. setstartbefore (EL );
Htmlfrag = RNG. createcontextualfragment (content );
While (El. haschildnodes () // clear the original content and add new content
El. removechild (El. lastchild );
El. appendchild (htmlfrag );

29. img src refresh
In IE, you can use can refresh the image, but not in Firefox. The main issue is caching. Add a random number after the address to solve the problem. The onclick event editing code is as follows: "This. src = This. SRC + '? '+ Math. Random ()"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.