JS's IE and Firefox compatibility assembly

Source: Internet
Author: User
Tags empty eval tagname variable access
Js

Following IE instead of Internet Explorer, MF replaces Mozzila Firefox

  1. Document.form.item question

(1) Existing problems:

There are many Document.formName.item ("itemname") statements in existing code that cannot be run under MF

(2) Solution:

Switch to document.formname.elements["ElementName"]

(3) Other

See also 2

  2. Collection Class object problem

(1) Existing problems:

Many collection class objects in existing code use (), IE can accept, MF cannot.

(2) Solution:

Use [] as the subscript operation instead. For example: Document.forms ("FormName") changed to document.forms["FormName"].

Also as follows: Document.getelementsbyname ("InputName") (1) Changed to Document.getelementsbyname ("InputName") [1]

(3) Other

  3. window.event

(1) Existing problems:

Unable to run on MF using window.event

(2) Solution:

MF event can only be used at the scene of the incident, this problem can not be resolved. You can do this:

Original code (can run in IE):

<input type= "button" Name= "Somebutton" value= "Submit"/>
...
<script language= "JavaScript" >
function Gotosubmit () {
...
alert (window.event); Use window.event
...
}
</script>

New code (can run in IE and MF):

<input type= "button" Name= "Somebutton" value= "Submit"/>
...
<script language= "JavaScript" >
function Gotosubmit (evt) {
EVT = evt? EVT: (window.event window.event:null);
...
alert (EVT); Use EVT
...
}
</script>

In addition, if the first line in the new code does not change, the same as the old code (that is, the gotosubmit call does not give the parameter), it still can only run in IE, but not error. Therefore, the TPL part of this scheme is still compatible with the old code.

  4. The ID of an HTML object as an object name problem

(1) Existing problems

In IE, the ID of an HTML object can be used directly as the subordinate object variable name of document. Not in MF.

(2) Solving method

Use getElementById ("Idname") instead of Idname as an object variable.

  5. Obtaining an object with a idname string

(1) Existing problems

In IE, you can use Eval (idname) to obtain an HTML object with an ID of idname, which cannot be in MF.

(2) Solving method

Replace eval (idname) with getElementById (Idname).

  6. Variable name and an HTML object ID the same problem

(1) Existing problems

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.

(2) Solving method

In the declaration of variables, all add Var, to avoid ambiguity, so that in IE can also be normal operation.

In addition, it is best not to take variable names that are the same as the HTML object IDs to reduce errors.

(3) Other

See question 4

  7. Event.x and EVENT.Y issues

(1) Existing problems

In IE, the event object has an X, y attribute, which is not in MF.

(2) Solving method

In MF, the equivalent of Event.x is Event.pagex. But Event.pagex ie did not.

Therefore, the use of Event.clientx instead of event.x. This variable is also available in IE.

There are subtle differences between Event.clientx and Event.pagex (when the entire page has a scroll bar), but most of the time it is equivalent.

If you want to be exactly the same, you can be a little more troublesome:

MX = Event.x? Event.x:event.pagex;

And then use MX instead of event.x.

(3) Other

Event.layerx in IE and MF, the specific meaning of the difference has not yet been tested.

  8. About Frame

(1) Existing problems

In IE, you can use Window.testframe to get the FRAME,MF.

(2) Solving method

The main differences between MF and IE in the use of frame are:

If the following attributes are written in the frame label:

<frame src= "xx.htm" id= "Frameid" name= "FrameName"/>

Then IE can access the Window object for this frame 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 top-level window, you can access the

Ie:window.top.frameId or Window.top.frameName to access this window object

MF: Only so window.top.frameName to access this window object

In addition, Window.top.document.getElementById ("Frameid") can be used in both MF and IE to access the frame label

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 '

A description of frame and window can be found in the ' window and frame ' article of BBS

And the test below the/test/js/test_frame/directory.

----Adun 2004.12.09 Revision

  9. In MF, the attribute defined by itself must be getattribute () to obtain

  10. No parentelement Parement.children in Mf

ParentNode Parentnode.childnodes

ChildNodes the meaning of the subscript is different in IE and MF, MF uses the DOM specification, ChildNodes inserts a blank text node.

It is generally possible to avoid this problem by Node.getelementsbytagname ().

When nodes in HTML are missing, IE and MF have different interpretations of parentnode, such as

<form>
<table>
<input/>
</table>
</form>

The value of Input.parentnode in MF is form, while the value of Input.parentnode in IE is an empty node

There is no Removenode method for nodes in MF, you must use the following method Node.parentNode.removeChild (node)

  11.const problem

(1) Existing problems:

The Const keyword cannot be used in IE. such as const CONSTVAR = 32; This is a syntax error in IE.

(2) Solution:

Do not use const instead of Var.

  A. Body Object

MF body in the body tag is not fully read by the browser before the existence, and IE must be completely read into the body after the existence of

  URL encoding

In JS if the write URL directly write & do not write & such as var url = ' xx.jsp?objectname=xx&objectevent=xxx ';

Frm.action = URL It is likely that the URL will not be displayed properly so that the parameter is not uploaded to the server correctly

General Server error parameter not found

Of course, if the exception is in the TPL, because the TPL conforms to the XML specification, the requirement & write as &

General MF cannot recognize the & in JS

  NodeName and TagName issues

(1) Existing problems:

In MF, all nodes have nodename values, but textnode do not have tagName values. In IE, the use of nodename is as good as

There is a problem (the situation is not tested, but my IE has been dead several times).

(2) Solution:

Use TagName, but you should detect if it is empty.

  15. Element attributes

IE under the Input.type property is read-only, but MF can be modified

  Problems with Document.getelementsbyname () and Document.all[name]

(1) Existing problems:

In IE, Getelementsbyname (), Document.all[name] can not be used to obtain DIV elements (whether there are other elements that cannot be taken is unknown).



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.