Summary of compatibility issues in javascript ie and FF

Source: Internet
Author: User

Png transparentAlphaImageLoader
Filter: progid: DXImageTransform. Microsoft. AlphaImageLoader (enabled = bEnabled, sizingMethod = sSize, src = sURL)

Enabled: Optional. Boolean ). Set or retrieve whether the filter is activated. True: default value. Filter activation. False: the filter is disabled.
SizingMethod: Optional. String ). Sets or retrieves the display mode of the image of the object to which the filter applies within the boundary of the object container. Crop: Cut the image to fit the object size. Image: default value. Increase or decrease the size boundary of an object to fit the image size. Scale: scale the image to adapt to the size boundary of the object.
Src: required. String ). Specify the background image using an absolute or relative url. If this parameter is ignored, the filter will not work.

Firefox cannot support innerText
Firefox supports innerHTML but does not support innerText. It supports textContent to implement innerText, but by default, redundant spaces are retained. If textContent is not required, you can use innerHTML instead if the string does not contain HTML code.

Disable webpage Content Selection
Js: obj. onselectstart = function () {return false;} is generally used in IE ;}
Firefox uses CSS:-moz-user-select: none

Filter support (for example, transparent filter)
IE: filter: alpha (opacity = 10 );
Firefox:-moz-opacity:. 10;

Capture events
IE: obj. setCapture (), obj. releaseCapture ()
Firefox: document. addEventListener ("mousemove", mousemovefunction, true );
Document. removeEventListener ("mousemove", mousemovefunction, true );

Get mouse position
IE: event. clientX, event. clientY
Firefox: The event object needs to be passed by the event function.
Obj. onmousemove = function (ev ){
X = ev. pageX; Y = ev. pageY;
}

DIV and other element boundary issues
For example, set CSS ::{ width: 100px; height: 100px; border: #000000 1px solid;} Of a div ;}
In IE: div width (including Border width): 100px, div height (including Border width): 100px;
Firefox: div width (including Border width): 102px, div height (including Border width): 102px;

Determine the browser type
Var isIE = document. all? True: false;
I wrote a variable. If the document. all syntax is supported, isIE = true; otherwise, isIE = false.

CSS processing in different browsers
Generally, it can be used! Important Uses css statements first (only supported by firefox)
For example: {border-width: 0px! Important; border-width: 1px ;}
In firefox, this element has no border, and the Border Width under IE is 1px.

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"].

Collection Object Problems
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.

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.

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: Use getElementById ("idName") to retrieve the HTML object with id as idName.

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.

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.

Input. type attribute Problems
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.

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: <input type = "button" onclick = "doSomething (event)"/>
<Script language = "javascript">
Function doSomething (evt ){
Var myEvent = evt? Evt: (window. event? Window. event: null)
...
}

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.

Event. srcElement
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.

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.

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.

Frame and iframe Problems
The following frame is used as an example:
<Frame src00000000xxx.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 both ieand firefox, you can use Upload upload Doc ument. getElementById ("frameId"). src = export xxx.html "or window. frameName. location = export xxx.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.

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.

Event Delegate 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 ()") in a unified manner, or document. body. onload = function () {/* here is the code */}
[Note] differences between functions

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.

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.

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:
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.

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 ";

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:
// 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.

Ul and ol list indent Problems
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.

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.

CSS rounded corner
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.

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.