Home >Web Front-end >JS Tutorial >Summary of JS script writing methods compatible with Firefox and IE browsers_javascript skills
1.window.event compatible script
function getEvent(){ //Get browser events, compatible with IE and FF writing methods
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;
}
Every time before using an event, Firefox needs to use getEvent() to get it, otherwise it will be empty
2. Shield the Form submission event
event.returnValue=false;// for IE
evt.preventDefault();//for firefox
3. Get Event source
var source=event.srcElement //IE
var source=event.target //firefox
4. Add event compatible writing
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. Firefox registration innerText writing method
//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: FireFox length must be added with "px", IE does not matter
7. Child controls 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, but in firefox it cannot be empty. Send(" ") should be used, otherwise a 411 error will occur