The FireFox and IE scripts are incompatible.
1. Windows. event compatible scripts
Function getEvent () {// get browser events, and be compatible with ie and ff expressions 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" & arg0.preventDefault & 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.target //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. Length: the length of FireFox must be "px". IE doesn't matter.
7. Sub-control under the parent control: IE is "children", 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.