Compatible with IE and FF

Source: Internet
Author: User
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.
For example: Document. getelementsbyname ("inputname") [0], document. Forms ["formname"]

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.
Example: Document. getelementbyid ("Itemid ")

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. event can only be run in IE, but not in Firefox, because Firefox Event can only be used in the event.
Solution: Use the (aevent) parameter on the function that triggers the event. For example
Objnode. onmouseover = function (aevent ){
VaR myevent = Window. event? Window. event. srcelement: aevent.tar get;
// Execute other actions
}

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 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 OBJ (OBJ = event. srcelement? Event. srcelement: event.targettoken used to replace event.tar get under firefox.

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 ("Itemid "). value = "some value ";

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 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. Example: parent.doc ument. form1.filename. value = "some value ";

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.

For example:
Firefox: program code <body>
<SCRIPT type = "text/JavaScript">
Document. Body. onclick = function (EVT ){
EVT = EVT | window. event;
Alert (EVT );
}
</SCRIPT>
</Body>

 
IE & Firefox: program code <body>
</Body>
<SCRIPT type = "text/JavaScript">
Document. Body. onclick = function (EVT ){
EVT = EVT | window. event;
Alert (EVT );
}
</SCRIPT>

15. nodename and tagname Problems

Problem: In MF and IE, all nodes have a nodename value, but textnode does not have a tagname value.
Solution: Use tagname, but check whether it is undefined.

16. url Encoding

Q: In JS, if the URL is written, write directly & do not write & for example, VAR url = 'xx. jsp? Objectname = XX & objectevent = XXX ';
FRM. action = URL, it is very likely that the URL will not be properly displayed so that the parameter is not correctly transmitted to the server. Generally, the server reports an error that the parameter is not found. Of course, if it is an exception in TPL, because TPL complies with XML specifications, the requirements are as follows &
Generally, MF cannot recognize &

17. Children and childnodes, removenode

Problem 1: parentelement parement. Children is not found in MF and parentnode. childnodes is used.
Question 2: The meanings of childnodes are different from those of MF. MF uses Dom specifications, and blank text nodes are inserted in childnodes.
Question 3: You can avoid this problem by using node. getelementsbytagname. When a node in HTML is missing, ie and MF have different interpretations of parentnode, for example
<Form>
<Table>
<Input/>
</Table>
</Form>
In MF, the value of input. parentnode is form, while that of input. parentnode in IE is empty.

Problem 4: The node in MF does not have the removenode method. You must use the following method: node. parentnode. removechild (node)

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.