Home > Web Front-end > JS Tutorial > JS script compatible with Firefox browser

JS script compatible with Firefox browser

黄舟
Release: 2016-12-14 16:00:23
Original
1436 people have browsed it

I recently worked on a project and encountered the problem of incompatibility between FireFox and IE scripts. For this purpose, I collected some compatible scripts from the Internet. I also explored a bit myself. I originally wrote them in another blog of my own. I have copied them here for future reference. For reference, the original text

1. window.event compatible script
2. Shield the Form submission event
3. Get the event source
4. Add event compatible writing
5. Firefox registration innerText writing
6. Length
7. Under the parent control Sub-control
8. ;

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;
}

Firefox needs to use getEvent() to get it every time before using the event, otherwise it will be empty

2. Block the Form submission event

event.returnValue=false;// for IE

evt. preventDefault();//for firefox

3. Get the event source

var source=event.srcElement //IE

var source=event.target //firefox

4. Add event compatible writing method

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. The child controls under the parent control are "children" in IE and "childNodes" in FireFox

8. Send(" ") should be used, otherwise a 411 error will occur

For more related articles, please pay attention to the PHP Chinese website (m.sbmmt.com)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template