search
HomeWeb Front-endJS TutorialSummary of compatible JavaScript writing methods under IE and Firefox_javascript skills

1. It is found that the id attribute of the input tag under IE is the same as the name attribute by default, but Firefox must clearly write the name of the id attribute, otherwise the id attribute cannot be used.
For example:
The following code can be executed under IE but not under Firefox:


It must be changed to the following code:

The following is reproduced: 1. document.formName.item("itemName") Problem

Explanation: Under IE, you can use document.formName.item("itemName") or document .formName.elements["elementName"];
Under Firefox, you can only use document.formName.elements["elementName"].
Solution: Use document.formName.elements["elementName"] uniformly.
2. Problems with collection objects

Explanation: Under IE, you can use () or [] to obtain collection objects; under Firefox, you can only use [] to obtain collection objects.
Solution: Use [] uniformly to obtain collection class objects. 3. Custom attribute problem

Explanation: Under IE, you can use the method of obtaining regular attributes to obtain custom attributes, or you can Use getAttribute() to get custom attributes; under Firefox, you can only use getAttribute() to get custom attributes.
Solution: Get custom attributes through getAttribute(). 4.eval(" idName") problem

Explanation: Under IE, you can use eval("idName") or getElementById("idName") to obtain the HTML object with the id idName; under Firefox, you can only use getElementById("idName" ) to obtain the HTML object with the id of idName.
Solution: Use getElementById("idName") uniformly to obtain the HTML object with the id of idName.
5. The variable name is the same as the ID of an HTML object Problem

Explanation: Under IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document; but not under Firefox. Under Firefox, the same variable name as the HTML object ID can be used; but not under IE. .
Solution: Use document.getElementById("idName") instead of document.idName. It is best not to use variable names with the same HTML object ID to reduce errors; always add var when declaring variables to avoid ambiguity.
6.const problem

Explanation: Under Firefox, you can use the const keyword or the var keyword to define constants; under IE, you can only use the var keyword to define constants.
Solution: Use the var keyword uniformly to define constants.
7. Input.type attribute problem

Explanation: The input.type attribute under IE is read-only; but the input.type attribute under Firefox For reading and writing.
8.window.event problem

Explanation: window.event can only be run under IE, but not Firefox. This is because Firefox’s event can only be run under Used on-site where the event occurs. Firefox must add the event from the source for parameter passing. Ie ignores this parameter and uses window.event to read the event.
Solution:
IE&Firefox:
Submitted(event)"/> …

window.open("b.html","","modal=yes,width =500,height=500,resizable=no,scrollbars=no");
9.event.x and event.y issues

Explanation: Under IE, the even object has x, y attributes, but there are no pageX, pageY attributes; under Firefox, the even object has pageX, pageY attributes, but no x, y attributes. Solution: Use mX (mX = event.x ? event.x : event.pageX; ) to replace the event. ;Under Firefox, the even object has a target attribute, but no srcElement attribute.
Solution: Use obj (obj = event.srcElement? event.srcElement: event.target;) to replace event.srcElement under IE or under Firefox event.target. Please also pay attention to the compatibility issues of event

11.window.location.href issue
Note: Under IE or Firefox2.0.x, you can use window.location. Or window.location.href; under Firefox1.5.x, only window.location can be used. Solution: Use window.location instead of window.location.href.

12. Modal and Non-modal window problem
Explanation: Under IE, modal and non-modal windows can be opened through showModalDialog and showModelessDialog; but not under Firefox. Solution: Use window.open(pageURL,name directly , parameters) to open a new window.
If you need to pass the parameters in the child window back to the parent window, you can use window.opener in the child window to access the parent window. For example: var parWin = window.opener; parWin.document .getElementById("Aqing").value = "Aqing";

13.Frame problem
Take the following frame as an example:

(1) Access Frame object: IE: Use window.frameId or window.frameName to access this frame object. frameId and frameName can have the same name.
Firefox: You can only use window.frameName to access this frame object.
In addition, you can use window.document.getElementById("frameId") to access this frame object in both IE and Firefox.
( 2) Switch frame content:
You can use window.document.getElementById("testFrame").src = "xxx.html" or window.frameName.location = "xxx.html" to switch frame in both IE and Firefox content.
If you need to pass the parameters in the frame back to the parent window (note that it is not the opener, but the parent frame), you can use parent in frme to access the parent window.For example: parent.document.form1.filename.value="Aqing";
14.body problem
Firefox’s body exists before the body tag is fully read by the browser; and The body of IE must exist after the body tag is completely read by the browser.
15. Event delegation method
IE: document.body.onload = inject; //Function inject( ) has been implemented before
Firefox: document.body.onload = inject();
16. The difference between the parent element (parentElement) of firefox and IE
IE: obj .parentElement
firefox: obj.parentNode
Solution: Because both firefox and IE support DOM, using obj.parentNode is a good choice.
17.cursor:hand VS cursor:pointer
Firefox does not support hand, but IE supports pointer
Solution: Use pointer uniformly
18. innerText can work normally in IE, but innerText does not work in FireFox. TextContent is required.
Solution:
if(navigator.appName.indexOf("Explorer") > -1){
document.getElementById('element').innerText = "my text";
} else{
document.getElementById('element').textContent = "my text";
}
19. When setting the style of HTML tags in FireFox, all positionalities and font sizes The value of must be followed by px. This ie is also supported.
20. IE, Firefox and other browsers have different operations on table tags. In IE, innerHTML assignment of table and tr is not allowed. When using js to add a tr, the appendChild method does not work.

Solution:
//Append an empty row to the table:
var row = otable.insertRow(-1);
var cell = document.createElement("td");
cell.innerHTML = " ";
cell.className = "XXXX";
row.appendChild(cell);
21. padding problem
padding 5px 4px 3px 1px FireFox cannot interpret the abbreviation,
must be changed to padding-top:5px; padding-right:4px; padding-bottom:3px; padding-left:1px;
22. Eliminate ul, ol, etc. When indenting a list, the
style should be written as: list-style:none;margin:0px;padding:0px;
where the margin attribute is valid for IE and the padding attribute is valid for FireFox
23. CSS transparency
IE: filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60).
FF:opacity:0.6.
24. CSS rounded corners
IE: Rounded corners are not supported.
FF: -moz-border-radius:4px, or -moz-border-radius-topleft:4px;-moz-border-radius-topright:4px;-moz-border-radius-bottomleft:4px;-moz -border- radius- bottomright:4px;.
25. CSS double line bump border
IE: border:2px offset;.
FF: -moz-border-top-colors: #d4d0c8 white;-moz-border-left-colors: #d4d0c8 white;-moz-border-right-colors:#404040 #808080;-moz-border- bottom-colors: #404040 #808080;
26. Operation on the options collection of select
In addition to [], selectName.options.item() is also available for enumeration elements. In addition, selectName .options.length, selectName.options.add/remove can be used on both browsers. Pay attention to assigning elements after add, otherwise it will fail (this is what I tested).
27. The difference between XMLHTTP
//mf
if (window.XMLHttpRequest) //mf
{
xmlhttp=new XMLHttpRequest()
xmlhttp.
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
}
//ie
else if (window.ActiveXObject) // code for IE
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.
xmlhttp.open("GET",url,true)
xmlhttp.send()
}
}
}
28. The difference between innerHTML
Firefox does not support innerHTML, the solution can be as follows
rng = document .createRange();
el = document.getElementById(elementid);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content);
while (el.hasChildNodes()) //Clear the original content and add new content
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
29. img src refresh problem
You can use Summary of compatible JavaScript writing methods under IE and Firefox_javascript skills to refresh the image under IE, but not under FireFox. It's mainly a caching problem, which can be solved by adding a random number after the address. Edit the onclick event code as follows: "this.src=this.src '?' Math.random()"

Statement
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
JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),