JS script compatibility in IE/Firefox

Source: Internet
Author: User
Tags configuration settings
1. document. form. item/document. ID
Document. formName. item ("itemName") in IE ")
Document. formName. elements ["elementName"] in FF
We recommend that you use document. getElementById (itemName)
2. subscript operation
Document. forms ("formName") in IE ")
Document. forms ["formName"] in FF
Document. getElementsByName ("inputName") (1) in IE)
Document. getElementsByName ("inputName") in FF [1]
We recommend that you use [] as the subscript operation.
3, window. event
Window. event can be used in IE
In FF, the event can only be used at the scene where the event occurred, and can be rewritten to the event = function (event );
Function somemethod (evt ){
Evt = evt? Evt: (window. event? Window. event: null );
Alert (evt );
}
Example: <input onclick = somemethod (event)>
4. event. x and event. y
In IE, the event object has the x and y attributes.
FF, can be replaced by event. clientX, event. clientY (IE also has this attribute)
Also available: mX = event. x? Event. x: event. pageX;
5. Operate the frame
In IE, you can use window. FrameName to obtain the frame, but not in FF.
In FF, you can access the frame by using Comment comment top.doc ument. getElementById ("frameId ").
Note: Both IE and ffcan pass through zookeeper top.doc ument. getElementById ("Frame "). src = 'somefile.htm' to switch the frame content, you can also use window. top. frameName. location = 'somefile.htm' to switch the frame content
6. Call showModalDialog.
In IE, you can use showModalDialog to create a subwindow and obtain the returned value.
There is no showModalDialog in FF, but it can be implemented using window. open.
For example:
The Main. cfm file contains the following code:
Function ShowItemList (Obj ){
If (document. all) {// IE
Var ReturnValue = window. showModalDialog ("ItemList. cfm? Id = 341 "," self "," dialogwidth: 500px; status: false ");
If (typeOf (ReturnValue )! = 'Undefined '){
Obj. value = ReturnValue;
}
}
Else {
Var subwin = window. open (Item. cfm? Id = 341, 'newwin', 'modal = yes, width = 500px ');
}
}
Function ReturnValue (ReturnValue ){
Obj = document. getElementById ('elementname ');
Obj. value = ReturnValue;
}
If you want to get the return value, you need to use the parameter modal = yes of window. open, and you must pass the value (window. opener) to the parent window in the subwindow ).
For example, add the following code to subwin. cfm:
Function ReturnThisValue (){
Window. opener. ReturnValue (document. getElementById ('selecteditem'). value );
}
7. Others
A. In FF, the custom attribute must use getAttribute ()
If parentElement parement. children is not found in B and FF, use parentNode. childNodes. You can use node. getElementsByTagName ()
C, FF does not support onpropertychange events
In d and FF, createElement does not support HTML code. You can use: document. write (esHTML );
E, innerText in IE, textContent can be used in FF
F and FF use class to replace the className in IE
G. If FF calls obj. focus (); and an error is returned, change it to window. setTimeout (function () {obj. focus () ;}, 0 );
H. firefox does not support FILTER.
I, IE: blur occurs after focus, FF: blur occurs before focus
J. IE: event. keyCode ==== FF: event. which
Function catcathevent (evt)
{
Evt = evt? Evt: (window. event? Window. event: null );
If (document. all ){
Var keyvalue = evt. keyCode;
}
Else {
Var keyvalue = evt. which;
}
K. Set the left, top, and length and width of the container location. 'px 'must be added, for example, $ ('obj'). style. left = '50px ';
L. Enter about: config in the FF address bar, and Firefox's parameter configuration settings will appear.

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.