Differences between IE and Firefox JS

Source: Internet
Author: User
 

1.ObjectProblem
1.1 form object

Existing problems:
ExistingCodeIn this way, the form object is obtained through document. Forms ("formname"), which is accepted by IE.
No.
SolutionMethod:
Use as subscript. Change to document. Forms ["formname"]
Remarks
Use
In subscript calculation, formname is ID and name

1.2HtmlObject
Existing problems:
In ie, the ID of the HTML object can be
The variable name of the subordinate object of document is used directly. In MF
.
Document. All ("itemname") or document. All ("Itemid ")
Solution:
Use the Object ID as the object variable name
Document. getelementbyid ("Itemid ")
Remarks
Document. All is a custom ie method, so try not to use it.
Another method is available in both IE and MF.
VaR
F = Document. Forms ["formname"];
VaR o = f. Itemid;

1.3 Div object

Existing problems:
In ie, the DIV object can use ID directly as the object variable name. It cannot be in MF.
Divid. style. Display =
"None"
Solution:
Document. getelementbyid ("divid"). style. Display =
"None"
Remarks
The getelementbyid method is used to obtain the object, whether it is a div object or not. See 1.2

1.4
About Frame
Existing Problems
In IE
You can use window. testframe to obtain the frame, but not in MF.
Solution
The main difference between MF and IE in frame usage is:
If the following attributes are written in the frame tag:

Then Ie can access the window object corresponding to this frame through ID or name.
However, MF can only access the window object corresponding to this frame through name.
For example, if the above frame label is written in the HTM in the top window, you can access
IE:
Window. Top. frameid or window. Top. framename to access this window object
Mf: only window. Top. framename can access this window object.
In addition, both mfand iecan use javasdesktop.doc ument. getelementbyid ("frameid") to access the frame tag.
In addition, you can use the parameter top.doc ument. getelementbyid ("testframe"). SRC
= 'Xx.htm' to switch the frame content
You can also use window. Top. framename. Location =
'Xx.htm' to switch the frame content

Window 1.5

Existing Problems
In IE, you can use showmodaldialog and showmodelessdialog to open modal and non-modal windows, but MF does not.
Solution
Use window. Open (pageurl, name, parameters) to open a new window.
If you want to pass parameters, you can use frame or IFRAME.

2.
Summary
2.1 when defining various object variable names in JS, use ID whenever possible to avoid using name.
In ie, the ID of an HTML object can be used as a document
Variable names of subordinate objects are directly used. It cannot be used in MF. Therefore, use ID whenever possible to avoid using only name instead of ID.

2.2 variable names and an HTML Object
Issues with the same ID
Existing Problems
In MF, because the Object ID is not the name of the HTML object, you can use the same variable name as the HTML Object ID, ie
.
Solution
When declaring variables, add VaR to avoid ambiguity, so that it can run normally in IE.
In addition, it is best not to obtain the ID of an HTML Object
The same variable name to reduce errors.

1. Document. All
Firefox is compatible with document. All,
However, a warning is generated. You can use getelementbyid ("*") or
Instead of getelementbytagname ("*)
However, attributes such as document. All. length are completely incompatible.
2.
Parentelement
This is also incompatible. For example, obj. parentelement. name should be changed
OBJ. parentnode. Attributes. getnameditem ("name"). nodevalue (I don't know how to write it more concisely)
3.
Event
W3C does not support windows. Event
For example:
In IE

judge the browser navigator. appname = "Microsoft Internet Explorer"
navigator. useragent. indexof ("MSIE")> 0
Firefox does not support
window. close ()
innertext textcontent
Firefox is only available in windows. window. close (); but if this page is IFRAME, it is recommended to use top. close.
children is not supported. childnodes is supported.
for XML reading in Firefox, pay attention to the 01234 sub-nodes in IE, firefox is 13579
ie
var opname = C. childnodes [0]. text;
var opid = C. childnodes [1]. text;
var opurl = C. childnodes [2]. text;
var opuser = C. childnodes [3]. text;
var opadress = C. childnodes [4]. text
FF
var opname = C. childnodes [1]. textcontent;
var opid = C. childnodes [3]. textcontent;
var opurl = C. childnodes [5]. textcontent;
var opuser = C. childnodes [7]. textcontent;
var opadress = C. childnodes [9]. textcontent;
but Firefox still supports chindnodes

In Firefox, the defined attributes must be obtained by getattribute ().
But do not change the value obtained by getattribute (), for example
VaR A = B. getattribute ("attribute ")
B. Attributes = 100
VaR c = B. getattribute ("attribute ")
Regardless of the number of B. Attributes changed, A and C are equal.
Recommended Operation Method
Global variable fag = 0;
If (FAG = 0)
Fag = B. Attribute = B. getattribute ("attribute ");

Firefox cannot write function A. B ()
{}
To be written as a. B = function (){}

Firefox does not support src = "file: // C: a.gif ";

XMLHTTP. setRequestHeader must be capitalized in Firefox

FF's Ajax and IE can be written in many ways, but FF may sometimes encounter errors. Below is a way to write without errors
function getdatafromserver (URL, ID)
{< br> If (window. XMLHttpRequest)
{ request = new XMLHttpRequest () ;}< br> else
If (window. activexobject)
{request = new activexobject ("msxml2.xmlhttp. 5.0 ") ;}< br> var serverurl = URL;
If (request)
{< br> window. status = "updating data .... ";
request. open ("get", serverurl, true);
request. setRequestHeader ("Content-Type", "application/X-WWW-form-

Urlencoded ");
Request. onreadystatechange = function () {onresponse (ID );};
Request. Send (null );


}
}
Function onresponse (ID)
{
VaR XMLHTTP = request;
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
VaR result = XMLHTTP. responsetext;
If (document. getelementbyid ("load _" + id ))
{
Logic;
}
Window. Status = "data updated ";
}
}
}

Datepicker, a date control for both IE and Firefox, is supported.

ie parentelement
Firefox parentnode

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.