Difference between javascript css in IE and Firefox

Source: Internet
Author: User

I. document. formName. item ("itemName ")
Problem description: in IE, 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"].

Ii. Collection objects
Problem description: 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.

Iii. Custom Attributes
Problem description: 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: Get custom attributes through getAttribute.

Iv. eval ("idName") Problems
Problem description: 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.
Problem description: in IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document, but not in Firefox. In Firefox, the variable name that is the same as the ID of the HTML object can be used, IE.
Solution: Use document. getElementById ("idName") to replace document. idName. We recommend that you do not use variable names with the same HTML Object ID to reduce errors. When declaring variables, add the var keyword to avoid ambiguity.

Vi. const Problems
Problem description: 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.

VII. input. type attributes
Problem description: The input. type attribute in IE is read-only, but the input. type attribute in Firefox is read/write.
Solution: do not modify the input. type attribute. If you must modify it, You can first hide the original input, and then insert a new input element at the same position.

8. window. event Problems
Problem description: window. event can only be run in IE, but not in Firefox, because Firefox event can only be used in the event.
Solution: add the event parameter to the function where the event occurs and use var myEvent = evt? Evt :( window. event? Window. event: null)
Example:Copy codeThe Code is as follows: <input type = "button" onclick = "doSomething (event)"/>
<Script language = "javascript">
Function doSomething (evt ){
Var myEvent = evt? Evt :( window. event? Window. event: null)
...
}

9. event. x and event. y
Problem description: 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: var myX = event. x? Event. x: event. pageX; var myY = event. y? Event. y: event. pageY;
If you consider 8th issues, use myEvent instead of event.

10. event. srcElement Problems
Problem description: in IE, the even 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 srcObj = event. srcElement? Event. srcElement: event.tar get;
If you consider 8th issues, use myEvent instead of event.

11. window. location. href
Problem description: 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. Of course, you can also consider using the location. replace () method.

12. Modal and non-modal window Problems
Problem description: in IE, you can open modal and non-modal windows through showModalDialog and showModelessDialog; in Firefox, you cannot.
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. opener in the Child window to access the parent window. If you need a parent window to control the child window, use var subWindow = window. open (pageURL, name, parameters); to obtain the new window object.

13. frame and iframe Problems
The following frame is used as an example:
<Frame src = "http://www.52css.com/123.html" id = "frameId" name = "frameName"/>
(1) access the frame object
IE: Use window. frameId or window. frameName to access this frame object;
Firefox: Use window. frameName to access this frame object;
Solution: You can access the frame object by using the metadata Doc ument. getElementById ("frameId;
(2) Switching frame content
In ieand firefox, you can use javasecondoc ument. getElementById ("frameId"). src = "52css.com.html" or window. frameName. location = "52css.com.html" to switch the frame content;
If you want to return the parameters in the frame to the parent window, you can use the parent keyword in the frame to access the parent window.

14. body Loading Problems
Problem description: Firefox's body object exists before the body tag is fully read by the browser, While IE's body object must exist after the body tag is fully read by the browser.
[Note] the problem has not been verified. You can modify it after verification.
[Note] It has been verified that IE6, Opera9, and FireFox2 do not have the above problems. A simple JS script can access all objects and elements that have been loaded before the script, this element is not loaded yet.

15. Event delegation Method
Problem description: Use document in IE. body. onload = inject; function inject () has been implemented before this; in Firefox, use document. body. onload = inject ();
Solution: Use document. body. onload = new Function ('inject () '); or document. body. onload = function () {/* here is the code */}
[Note] differences between functions

16. Differences between parent elements for access
Problem description: in IE, use obj. parentElement or obj. parentNode to access the parent node of obj. In firefox, use obj. parentNode to access the parent node of obj.
Solution: because both firefox and IE support DOM, obj. parentNode is used to access the parent node of obj.

17. cursor: hand VS cursor: pointer
Problem description: firefox does not support hand, But ie supports pointer. Both are hand-shaped indicators.
Solution: Use pointer in a unified manner.

18. innerText problems.
Problem description: innerText works normally in IE, but innerText does not work in FireFox.
Solution: Use textContent instead of innerText in a non-IE browser.
Example:Copy codeThe Code is as follows: if (navigator. appName. indexOf ("Explorer")>-1 ){
Document. getElementById ('element'). innerText = "my text ";
} Else {
Document. getElementById ('element'). textContent = "my text ";
}

[Note] innerHTML is supported by ie, firefox, and other browsers at the same time. Others, such as outerHTML, are only supported by ie, so it is best not to use it.

19. Assignment of object width and height
Problem description: The statement similar to obj. style. height = imgObj. height in FireFox is invalid.
Solution: Use obj. style. height = imgObj. height + 'px ';

20. Table Operation Problems
Problem description: operations on table labels vary with ie, firefox, and other browsers. in ie, assignment of innerHTML values to table and tr is not allowed. When a tr value is added to js, the appendChild method does not work.
Solution:Copy codeThe Code is as follows: // 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 );

[Note] I have never encountered this problem because I rarely use JS to directly operate on tables. We recommend that you use the JS framework set to operate tables, such as JQuery.

Ii. Questions about ul and ol list indentation
When the indentation of ul and ol lists is eliminated, the 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. This sentence is incorrectly expressed. For details, refer to the statement.
[Note] the problem has not been verified. You can modify it after verification.
[Note] It has been verified that in IE, setting margin: 0px can remove indentation, white spaces, list numbers, or dots from the top, bottom, and right of the list. Setting padding does not affect the style. In Firefox, setting margin: 0px can only remove the upper and lower spaces. After setting padding: 0px, only the left and right indentation can be removed. You must also set list-style: none to remove list numbers or dots. In other words, you can set only margin: 0px in IE to achieve the final effect. In Firefox, you must set both margin: 0px, padding: 0px, and list-style: none can achieve the final effect.

Ii. CSS transparency
IE: filter: progid: DXImageTransform. Microsoft. Alpha (style = 0, opacity = 60 ).
FF: opacity: 0.6.
[Note] it is best to write both of them and put the opacity attribute below.

Ii. CSS rounded corners
IE: ie7 or earlier versions do not support rounded corners.
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 ;.
[Note] the rounded corner problem is a classic issue in CSS. We recommend that you use the JQuery framework set to set the rounded corner so that you can leave these complicated problems for others to think about.

There are too many questions about CSS, and even the display effects of the same CSS definition in different page standards are different. For more information, see the article 52CSS.com. A developing suggestion is that pages are written in the standard DHTML standard, with fewer tables. CSS definitions should follow the standard DOM as much as possible, while taking into account mainstream browsers such as IE, Firefox, and Opera. BTW, in many cases, FF and Opera's CSS interpretation standards are closer to CSS standards and more normative.

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.