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" & 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.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. 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.