JavaScript's IE and Firefox compatibility Assembly __java

Source: Internet
Author: User
JavaScript's IE and Firefox compatibility assembly Author: yaosansi Date: 2006-11-14

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" onclick= "Javascript:gotosubmit ()"/>
...
<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" onclick= "Javascript:gotosubmit" (event)/>
...
<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.
Add to the original: the object of the event, in IE is window.event.srcElement, in Firefox is Event.target, and in opera both support. Or use examples to illustrate.
Event.srcelement/event.target

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.