Compatibility between IE and Firefox in Javascript)

Source: Internet
Author: User
Compatibility between IE and Firefox in Javascript

1.doc ument. 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"].
Text1:
Document. formname. Item ("itemname ")
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.
Text2:
Document. Forms ("formname ")
Document. Forms ["formname"]
Text3:
Document. getelementsbyname ("inputname") (0)
Document. getelementsbyname ("inputname") [0]

-------------------------------------------------
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 () to obtain custom attributes.
Solution:
Getattribute () is used to obtain custom attributes.
Text4:
Get the value of the custom property directly
Getattribute () is used to obtain the value of a custom attribute.

-------------------------------------------------
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, only getelementbyid ("idname") can be used to obtain the HTML object whose ID is idname.
Solution:
Getelementbyid ("idname") is used to obtain the HTML object whose ID is idname.
Text5:
Eval ("idname ")
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 directly used as the variable name of the subordinate object of the document;
Firefox cannot.
In Firefox, you can use the same variable name as the HTML Object ID;
IE.
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, constants can only be defined using the VaR keyword.
Solution:
Use the VaR keyword to define constants.

-------------------------------------------------
7. Input. Type attribute Problems
Note:
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:
IE:
<Input name = "button8_1" type = "button" value = "ie"/>
...
<Script language = "JavaScript">
Function gotosubmit8_1 (){
...
Alert (window. Event); // use window. Event
...
}
</SCRIPT>
IE & Firefox:
<Input name = "button8_2" type = "button" value = "ie"/>
...
<Script language = "JavaScript">
Function gotosubmit8_2 (EVT ){
...
EVT = EVT? EVT :( window. event? Window. Event: NULL );
Alert (EVT); // use EVT
...
}
</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 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;
Only window. location.
Solution
: Use window. location to replace window. Location. href.

-------------------------------------------------
12. Modal and non-modal window Problems
Note:
In ie, the modal and non-modal windows can be opened through showmodaldialog and showmodelessdialog;
Firefox 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.
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.
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 = "aqing ";

-------------------------------------------------
14. Body Problems
The Firefox body exists before the body tag is completely read by the browser;
The IE body must exist only after the body tag is fully read by the browser.
For example:
Firefox:
<Body>
<SCRIPT type = "text/JavaScript">
Document. Body. onclick = function (EVT ){
EVT = EVT | window. event;
Alert (EVT );
}
</SCRIPT>
</Body>
IE & Firefox:
<Body>
</Body>
<SCRIPT type = "text/JavaScript">
Document. Body. onclick = function (EVT ){
EVT = EVT | window. event;
Alert (EVT );
}
</SCRIPT>

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.