Compatible with JS scripts in Firefox

Source: Internet
Author: User
Recently I made a project and encountered the problem of incompatibility between FireFox and IE scripts. For this reason, I collected some compatible scripts from the Internet, and I also found out a little bit, I wrote it in another blog of my own and copied it for your reference. Recently I made a project and encountered the problem of incompatibility between FireFox and IE scripts, for this reason, I collected some compatible scripts from the Internet, and I also found out a little bit. I wrote them in my own blog and copied them for your reference.

1. Windows. event compatible scripts
2. Shield Form submission events
3. Obtain the event Source
4. Add event compatibility
5. How to register innerText in Firefox
6. Length
7. Child controls under the parent Control
8. XmlHttp

1. Windows. event compatible scripts

Function getEvent () {// gets browser events, and is compatible with ie and ff writing.
If (document. all) return window. event;
Func = getEvent. caller;
While (func! = Null ){
Var arg0 = func. arguments [0];
If (arg0 ){
If (arg0.constructor = Event arg0.constructor = MouseEvent)
(Typeof (arg0) = "object" % 26amp; % 26amp; arg0.preventDefault % 26amp; % 26amp; arg0.stopPropagation )){
Return arg0;
}
}
Func = func. caller;
}
Return null;
}

Before each event is used, Firefox needs to use getEvent () to obtain it. Otherwise, it is null.

2. Shield Form submission events

Event. returnValue = false; // for IE

Evt. preventDefault (); // for firefox

3. Obtain the event Source

Var source = event. srcElement // IE

Var source=event.tar get // firefox

4. Add event compatibility

Function addEvent (oElement, sEvent, func ){
If (oElement. attachEvent ){
OElement. attachEvent (sEvent, func );
}
Else {
SEvent = sEvent. substring (2, sEvent. length );
OElement. addEventListener (sEvent, func, false );
}
}

Usage addEvent (window, "onload", Start );

5. How to register innerText in Firefox

// Register firefox innerText
HTMLElement. prototype. _ defineGetter _ ("innerText ",
Function (){
Var anyString = "";
Var childS = this. childNodes;
For (var I = 0; I if (childS [I]. nodeType = 1)
AnyString + = childS [I]. tagName = "BR "? '\ N': childS [I]. innerText;
Else if (childS [I]. nodeType = 3)
AnyString + = childS [I]. nodeValue;
}
Return anyString;
}
);
HTMLElement. prototype. _ defineSetter _ ("innerText ",
Function (sText ){
This. textContent = sText;
}
);

6. The length of FireFox must be "px". IE doesn't matter.

7. The sub-control IE under the parent control is "children", and FireFox is "childNodes"

8. XmlHttp

In IE, the content of the XmlHttp. send (content) method can be empty, while firefox cannot be empty. send ("") should be used; otherwise, error 411 may occur.

For more related articles, refer to PHP Chinese website (www.php1.cn )!

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.