Get the App
SLTechnology News&Howtos  ›  Development  › 

How Firefox browsers are compatible with JS scripts

Shulou Source: shulou.com Published: 2022-06-02 14:01:48 09月26日 Update

This article shows you how Firefox browsers are compatible with JS scripts, which are concise and easy to understand. I hope you can gain something through the detailed introduction of this article.

I would like to describe to you the problem of Firefox browser compatibility with JS scripts. Recently, I have done a project and encountered the problem of incompatibility between FireFox and IE scripts. For this reason, I have collected some compatible scripts from the Internet, which I will share with you here.

Firefox browser is compatible with JS scripts for reference

1.window.event compatible script

FunctiongetEvent () {/ / gets browser events that are compatible with both ie and ff writing if (document.all) returnwindow.event; func=getEvent.caller; while (functionally null) {vararg0=func.arguments [0]; if (arg0) {if ((arg0.constructor==Eventarg0.constructor==MouseEvent) (typeof (arg0) = = "object" & & arg0.preventDefault&&arg0.stopPropagation)) {returnarg0;}} funcfunc=func.caller;} returnnull;}

Firefox needs to be fetched with getEvent () before each event, otherwise it will be empty.

two。 Block Form submission events

Event.returnValue=false;//forIE evt.preventDefault (); / / forfirefox

3. Get event source

Varsource=event.srcElement//IE varsource=event.target//firefox

4. Add event-compatible writing

FunctionaddEvent (oElement,sEvent,func) {if (oElement.attachEvent) {oElement.attachEvent (sEvent,func);} else {sEventsEvent=sEvent.substring (2 sEvent,func,false); oElement.addEventListener (sEvent,func,false);}}

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

5.Firefox registration innerText writing

/ register firefoxinnerText HTMLElement.prototype.__defineGetter__ ("innerText", function () {varanyString= ""; varchildS=this.childNodes; for (vari=0;iif (childcare [I] .nodeType = = 1) anyString+= childS[ I] .tagName = = "BR"?'\ nchildS.innerText; elseif (childS.nodeType = 3) anyString+= childS[ I] .nodeValue;} returnanyString;}); 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" and FireFox is "childNodes"

8.XmlHttp

In IE, the content of the XmlHttp.send (content) method can be empty, but the firefox cannot be empty. You should use send (""), otherwise a 411 error will occur.

The above is how Firefox browsers are compatible with JS scripts. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Scripts browsers browsing events writing content that is skills controls knowledge length problems concise for this it doesn't matter to the point at the same time articles methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Microsoft OPPO Reno MySQL