Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make Firefox fully compatible with Javascript scripts

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report