search
HomeWeb Front-endJS TutorialAnalysis of the difference between javascript css in IE and Firefox_javascript skills

1. Document.formName.item("itemName") problem
Problem description: Under IE, you can use document.formName.item("itemName") or document.formName.elements ["elementName" ]; Under Firefox, only document.formName.elements["elementName"] can be used.
Solution: Use document.formName.elements["elementName"] uniformly.

2. Problems with collection objects
Problem description: Under IE, you can use () or [] to obtain collection objects; under Firefox, you can only use [ ] to obtain collection objects. object.
Solution: Use [] uniformly to obtain collection objects.

3. Custom attribute issues
Problem description: Under IE, you can use the method of getting regular attributes to get custom attributes, or you can use getAttribute() to get custom attributes. ;Under Firefox, you can only use getAttribute() to obtain custom attributes.
Solution: Get custom attributes through getAttribute().

4. eval("idName") problem
Problem description: Under IE, you can use eval("idName") or getElementById("idName") to get the id as idName HTML object; under Firefox, you can only use getElementById("idName") to obtain the HTML object with id as idName.
Solution: Use getElementById("idName") uniformly to obtain the HTML object with the id of idName.

5. The problem that the variable name is the same as the ID of an HTML object
Problem description: Under IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of document. Under Firefox Otherwise; under Firefox, you can use the same variable name as the HTML object ID, 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; when declaring variables, always add the var keyword to avoid ambiguity.

6. Const problem
Problem description: 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. Problem with input.type attribute
Problem description: The input.type attribute under IE is read-only; but the input.type attribute under Firefox is read-write.
Solution: Do not modify the input.type attribute. If you must modify it, you can hide the original input first, and then insert a new input element at the same position.

8. Window.event problem
Problem description: window.event can only be run under IE, but not under Firefox. This is because Firefox’s event can only be run under Used at the scene of the incident.
Solution: Add the event parameter to the function where the event occurs, and use var myEvent = evt?evt:(window.event?window.event:null)
in the function body (assuming the formal parameter is evt) Example :
Copy code The code is as follows:



9. Problems with event.x and event.y
Problem description: Under IE, the even object has x and y attributes, but does not have pageX and pageY attributes; under Firefox, the even object has pageX , pageY attributes, but there are no x, y attributes.
Solution: var myX = event.x ? event.x : event.pageX; var myY = event.y ? event.y:event.pageY;
If you consider question 8, use myEvent instead Just replace event.

10. Event.srcElement problem
Problem description: Under IE, the even object has the srcElement attribute, but no target attribute; under Firefox, the even object has the target attribute, but no srcElement property.
Solution: Use srcObj = event.srcElement ? event.srcElement : event.target;
If you consider the 8th question, just use myEvent instead of event.

11. Window.location.href problem
Problem description: Under IE or Firefox2.0.x, you can use window.location or window.location.href; Firefox1. Under 5.x, only window.location can be used.
Solution: Use window.location instead of window.location.href. Of course, you can also consider using the location.replace() method.

12. Modal and non-modal window issues
Problem description: Under IE, modal and non-modal windows can be opened through showModalDialog and showModelessDialog; under Firefox, they cannot .
Solution: Use window.open(pageURL,name,parameters) directly to open a new window.
If you need to pass parameters in the child window back to the parent window, you can use window.opener in the child window to access the parent window. If you need the parent window to control the child window, use var subWindow = window.open(pageURL,name,parameters); to obtain the newly opened window object.

13. Frame and iframe issues
Take the following frame as an example:

 (1)Access frame object
 IE: Use window.frameId or window.frameName to access this frame object;
 Firefox: Use window .frameName to access this frame object;
Solution: Use window.document.getElementById("frameId") uniformly to access this frame object;
(2) Switch frame content
In both IE and Firefox You can use window.document.getElementById("frameId").src = "52css.com.html" or window.frameName.location = "52css.com.html" to switch the content of the frame;
If you need to change the frame The parameters are passed back to the parent window. You can use the parent keyword in the frame to access the parent window.

14. Body loading problem
Problem description: Firefox’s body object exists before the body tag is fully read by the browser; while IE’s body object must It does not exist until the body tag has been fully read by the browser.
[Note] This issue has not been actually verified and will be modified after verification.
[Note] It has been verified that the above problem does not exist in IE6, Opera9 and FireFox2. A simple JS script can access all objects and elements that have been loaded before the script, even if the element has not been loaded yet.

15. Event delegation method
Problem description: Under IE, use document.body.onload = inject; where function inject() has been implemented before; in Firefox Next, use document.body.onload = inject();
Solution: Use document.body.onload=new Function('inject()'); or document.body.onload = function(){/* Here is the code */}
[Note] The difference between Function and function

16. The difference between accessed parent elements
Problem description: Under IE, use obj .parentElement or obj.parentNode accesses the parent node of obj; under Firefox, use obj.parentNode to access the parent node of obj.
Solution: Because both firefox and IE support DOM, they use obj.parentNode to access the parent node of obj.

Seventeen. cursor:hand VS cursor:pointer
Problem description: Firefox does not support hand, but IE supports pointer, both of which are hand instructions.
Solution: Use pointer uniformly.

18. Problems with innerText.
Problem description: innerText can work normally in IE, but innerText does not work in FireFox.
Solution: Use textContent instead of innerText in non-IE browsers.
Example:
Copy code The code is as follows:

if(navigator.appName.indexOf("Explorer") >-1){
document.getElementById('element').innerText = "my text";
} else{
document.getElementById('element').textContent = "my text";
}

[Note] innerHTML is also supported by IE, Firefox and other browsers, and others, such as outerHTML It is only supported by IE, so it is best not to use it.

19. Object width and height assignment problem
Problem description: Statements similar to obj.style.height = imgObj.height in FireFox are invalid.
Solution: Use obj.style.height = imgObj.height 'px'; 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:


Copy code
The code is as follows: //Append one to the table Empty row: var row = otable.insertRow(-1); var cell = document.createElement("td");
cell.innerHTML = "";
cell.className = " XXXX";
row.appendChild(cell);


[Note] Since I rarely use JS to directly operate tables, I have never encountered this problem. It is recommended to use JS framework to operate tables, such as JQuery.


21. Issues with indentation of ul and ol lists

When eliminating the indentation of lists such as ul and ol, the style should be written as: list-style:none;margin:0px; padding:0px;
 The margin attribute is valid for IE, and the padding attribute is valid for FireFox. ←This sentence is incorrectly expressed. For details, see ↓
 [Note] This issue has not been actually verified and will be modified after verification. [Note] It has been verified that in IE, setting margin:0px can remove the upper, lower, left and right indents, blanks, and list numbers or dots of the list. Setting padding has no effect on the style; in Firefox, setting margin:0px only You can remove the top and bottom spaces. After setting padding:0px, you can only remove the left and right indents. You must also set list-style:none to remove list numbers or dots. In other words, in IE, only margin:0px can be set to achieve the final effect, while in Firefox, margin:0px, padding:0px and list-style:none must be set at the same time to achieve the final effect.

22. CSS transparency issue

IE: filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60).
FF:opacity:0.6.
[Note] It is best to write both and put the opacity attribute below.
23. CSS rounded corners problem

IE: versions below ie7 do not support rounded corners.
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;.
[Note] The rounded corner problem is a classic problem in CSS. It is recommended to use the JQuery frame set to set rounded corners and leave these complex issues to others. There are too many problems in CSS, and even the same CSS definition has different display effects in different page standards. For more knowledge, please refer to the article on 52CSS.com. A suggestion that is in line with development is that the page should be written using the standard DHTML standard, with less use of tables. CSS definitions should be based on the standard DOM as much as possible, taking into account mainstream browsers such as IE, Firefox, and Opera. BTW, in many cases, the CSS interpretation standards of FF and Opera are closer to the CSS standards and more normative.
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
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

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

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)