Reprint IE and Firefox get the difference between the object

Source: Internet
Author: User

1.1Form objects

Existing issues:
The existing code this obtains the Form object through Document.forms ("FormName"), so that the use can be accepted in IE, MF cannot.
Workaround:
Instead, use it as the subscript operation. Change to Document.forms["FormName"]
Note
Instead, the formname in the subscript operation is the ID and the name

1.2HTML objects

Existing issues:
In IE, the ID of an HTML object can be used directly as a subordinate object variable name for document. Not in MF.
document.all ("ItemName") or document.all ("ItemId")
Workaround:
Use object ID as object variable name
document.getElementById ("ItemId")
Note
Document.all is the method of IE customization, so please try not to use it.
There is also a way that can be used in IE and MF
varf=document.forms["FormName"];
Varo=f.itemid;

1.3DIV objects

Existing issues:
In IE, a div object can be used directly with an ID as an object variable name. Not in MF.
Divid.style.display= "None"
Workaround:
document.getElementById ("divID"). style.display= "None"
Note
The method of obtaining an object, whether it is a Div object or not, uses the getElementById method. See 1.2

1.4 About Frame

Existing issues
In IE, you can use Window.testframe to get the FRAME,MF.
Workaround
The main differences between MF and IE in the use of frame are:
If the following attributes are written in the frame tag:

Then IE can access this frame's window object by ID or name
MF can only access the window object of this frame through name.
For example, if the frame tag is written in the HTM inside the topmost window, you can access
IE:window.top.frameId or Window.top.frameName to access the Window object
MF: This is the only way to access the Window object Window.top.frameName
In addition, Window.top.document.getElementById ("Frameid") can be used in both MF and IE to access frame tags
And you can switch the contents of the frame by window.top.document.getElementById ("Testframe") src= ' xx.htm '.
You can also switch the contents of a frame by window.top.framename.location= ' xx.htm '

1.5 windows

Existing issues
In IE, modal and non-modal windows can be opened via ShowModalDialog and showModelessDialog, but MF is not supported.
Solutions
Open a new window directly using window.open (pageurl,name,parameters).
If you need to pass parameters, you can use a frame or an IFRAME.

2. Summary

2.1 When defining various object variable names in JS, use the ID as much as possible to avoid using name.

In IE, the ID of an HTML object can be used directly as a subordinate object variable name for document. Not in MF, so use the ID as much as possible in your usual use, and avoid using only name, not ID.

2.2 An issue with the same variable name as an HTML object ID

Existing issues
In MF, because the object ID is not the name of an HTML object, you can use the same variable name as the HTML object ID, which is not available in IE.
Workaround
When declaring variables, add var to avoid ambiguity, which can be run normally in IE.
In addition, it is best not to take the same variable name as the HTML object ID to reduce the error.

1.document.all

Firefox can be compatible with document.all, but generates a warning. Can be replaced with getElementById ("*") or Getelementbytagname ("*")
However, for attributes such as document.all.length, they are completely incompatible.

2.parentElement

This is not compatible either. For example, Obj.parentElement.name should be changed to Obj.parentNode.attributes.getNamedItem ("name"). NodeValue (don't know how to write more succinctly)

Reprint IE and Firefox get the difference between the object

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.