Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make Firefox fully compatible with Javascript scripts

Shulou Source: shulou.com Published: 2022-06-03 17:09:16 10月04日 Update

This article mainly explains "how to make Firefox fully compatible with Javascript scripts". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to make Firefox fully compatible with Javascript scripts".

In Web development and design, we often encounter compatibility problems between various browsers, of which IE and Firefox are the most common. For example, in IE, the content of the XmlHttp.send (content) method can be empty, while firefox cannot be empty, and send (") should be used, otherwise 411 errors will occur. Here are several ways to make Firefox fully compatible with Javascript, for reference only.

1.window.event compatible script

Function getEvent () {/ / gets browser events and is compatible with both ie and ff writing if (document.all) return window.event; func=getEvent.caller; while (functionally null) {var arg0=func.arguments [0] If (arg0) {if ((arg0.constructor==Event arg0.constructor== MouseEvent) (typeof (arg0) = = "object" & & arg0.preventDefault & & arg0.stopPropagation)) {return arg0;}} funcfunc=func.caller;} return null;}

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

two。 Block Form submission events

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 {sEventsEvent=sEvent.substring (2 sEvent,func,false); oElement.addEventListener (sEvent,func,false);}}

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

5.Firefox registration innerText writing

/ register firefox innerText HTMLElement.prototype.__defineGetter__ ("innerText", function () {var anyString = ""; var childS = this.childNodes; for (var item0; I if (childS [I] .nodeType = = 1) anyString + = "BR"?'\ n': childS [I] .innerText; else if (childSI] .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" and FireFox is "childNodes"

8.XmlHttp

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

Thank you for reading, the above is the content of "how to make Firefox fully compatible with Javascript scripts". After the study of this article, I believe you have a deeper understanding of how to make Firefox fully compatible with Javascript scripts, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Scripts events writing methods learning between content that is controls browsers errors length problems browsing for reference only indifferent compatibility and often development design Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Shulou Technology NVidia Docker