Home Web Front-end JS Tutorial Sorting out some JavaScript compatibility notes for IE and Firefox_javascript skills

Sorting out some JavaScript compatibility notes for IE and Firefox_javascript skills

May 16, 2016 pm 06:09 PM
ie compatibility Firefox

1. document.form.item problem
(1) Existing problem:
There are many statements like document.formName.item("itemName") in the existing code, which cannot be used in Firefox Run
(2) solution under (Firefox):
Use document.formName.elements["elementName"] instead
(3) For other
see 2
2. Collection Class object problems
(1) Existing problems:
Many collection class objects in the existing code use () when accessing them. IE can accept it, but Firefox cannot.
(2) Solution:
Use [] instead as subscript operation. For example: document.forms("formName") is changed to document.forms["formName"].
Another example: document.getElementsByName("inputName")(1) changed to document.getElementsByName("inputName")[1]
(3) Others
3. window.event
(1) Existing problems:
Using window.event cannot run on Firefox browser
(2) Solution:
Firefox’s event can only be used at the scene where the event occurs. This The problem cannot be solved yet. It can be modified like this:
Original code (can run in IE):

...

New code (can run in IE and Firefox):

...

In addition, if the first line in the new code does not change and is the same as the old code (that is, the gotoSubmit call does not give parameters), it will still only work in IE It runs but no errors occur. Therefore, the tpl part of this solution is still compatible with the old code.
4. The problem of using the id of the HTML object as the object name

(1) Existing problems
In IE, the ID of the HTML object can be used directly as the subordinate object variable name of the document. . Not in Firefox.
(2) Solution Use getElementById("idName") instead of idName as an object variable.
5. Problems with using idName string to obtain objects

(1) Existing problems
In IE, you can use eval(idName) to obtain the HTML object with idName. Not available in Firefox.
(2) Solution Use getElementById(idName) instead of eval(idName).
6. The problem that the variable name is the same as an HTML object id

(1) Existing problems
In Firefox, because the object id is not used as the name of the HTML object, it can be used The variable name that is the same as the HTML object id can be used in IE.
(2) Solution
When declaring variables, always add var to avoid ambiguity, so that it can also run normally in IE.
In addition, it is best not to take the same variable name as the HTML object id to reduce errors.
(3) Others See question 4
7. Event.x and event.y issues

(1) Existing issues
In IE, the event object There are x, y attributes, which are not available in Firefox.
(2) Solution
In Firefox, the equivalent of event.x is event.pageX. But event.pageX is not available in IE.
So event.clientX is used instead of event.x. This variable also exists in IE.
Event.clientX and event.pageX have subtle differences (when the entire page has scroll bars), but most of the time they are equivalent.
If you want to be exactly the same, you can have a little more trouble:
mX = event.x ? event.x : event.pageX;
Then use mX instead of event.x
(3) Others event.layerX exists in IE and Firefox. Whether there is any difference in specific meaning has not yet been tested.
8. About frame

(1) Existing problems
You can use window.testFrame to get the frame in IE, but not in Firefox
(2)Solution
The main difference between Firefox and IE in the use of frames is: If the following attributes are written in the frame tag:


Then IE can access the corresponding frame through id or name window object
and Firefox can only access the window object corresponding to this frame through name
For example, if the above frame tag is written in the htm inside the top window, then you can access
ie like this: window.top .frameId or window.top.frameName to access this window object
Firefox: This is the only way to access this window object via window.top.frameName
In addition, window.top.document can be used in both Firefox and IE. getElementById("frameId") to access the frame tag
and you can use window.top.document.getElementById("testFrame").src = 'xx.htm' to switch the content of the frame
, you can also use window. top.frameName.location = 'xx.htm' to switch the content of the frame
For descriptions of frame and window, please refer to the 'window and frame' article of bbs
and the test under the /test/js/test_frame/ directory ----adun 2004.12.09 modified

9. In Firefox, the attributes you define must be obtained by getAttribute()
10. In Firefox, there is no parentElement parement.children but use

parentNode parentNode.childNodes
The meaning of the subscript of childNodes is different in IE and Firefox. Firefox uses the DOM specification, and blank text nodes will be inserted into childNodes.
Generally, this problem can be avoided through node.getElementsByTagName().
When a node is missing in html, IE and Firefox interpret parentNode differently, for example




The value of input.parentNode in Firefox is form, while the value of input.parentNode in IE is an empty node
Node in Firefox does not have a removeNode method, you must use the following method node.parentNode.removeChild( node)
11.const issues
(1) Existing issues:
The const keyword cannot be used in IE. Such as const constVar = 32; This is a syntax error in IE.
(2) Solution:
Do not use const and use var instead.
12. body object
Firefox’s body exists before the body tag is fully read by the browser, while IE must exist after the body is fully read
13. url encoding
In js, if you write the url, just write it directly & don’t write it. For example, var url = 'xx.jsp?objectName=xx&objectEvent=xxx';
frm.action = url then It is very likely that the URL will not be displayed normally and the parameters are not correctly transmitted to the server
Generally, the server will report an error that the parameter is not found
Of course, the exception is if it is in tpl, because tpl conforms to the xml specification, the requirement & is written as &
Generally Firefox cannot recognize & in js , but textNode has no tagName value. In IE, there seems to be a problem with the use of nodeName
(I haven’t tested the specific situation, but my IE has died several times). (2) Solution: Use tagName, but should detect whether it is empty.

15. Element attributes

The input.type attribute is read-only under IE, but it can be modified under Firefox

16. document.getElementsByName() and document.all[name ] Problems
(1) Existing problems:
In IE, neither getElementsByName() nor document.all[name] can be used to obtain div elements (are there other elements that cannot be obtained? have no idea).
Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Comparison and difference analysis of Bluetooth 5.3 and 5.2 versions Comparison and difference analysis of Bluetooth 5.3 and 5.2 versions Dec 28, 2023 pm 06:08 PM

Nowadays, many mobile phones claim to support Bluetooth 5.3 version, so what is the difference between Bluetooth 5.3 and 5.2? In fact, they are essentially subsequent updated versions of Bluetooth 5, and there is not much difference in most performance and functions. The difference between Bluetooth 5.3 and 5.2: 1. Data rate 1 and 5.3 can support higher data rates up to 2Mbps. 2. While 5.2 can only reach a maximum of 1Mbps, it means that 5.3 can transmit data faster and more stably. 2. Encryption control enhancement 2. Bluetooth 5.3 improves encryption key length control options, improves security, and can better connect to access control and other devices. 3. At the same time, because the administrator control is simpler, the connection can be more convenient and faster, which is not possible in 5.2.

Solution to i7-7700 unable to upgrade to Windows 11 Solution to i7-7700 unable to upgrade to Windows 11 Dec 26, 2023 pm 06:52 PM

The performance of i77700 is completely sufficient to run win11, but users find that their i77700 cannot be upgraded to win11. This is mainly due to restrictions imposed by Microsoft, so they can install it as long as they skip this restriction. i77700 cannot be upgraded to win11: 1. Because Microsoft limits the CPU version. 2. Only the eighth generation and above versions of Intel can directly upgrade to win11. 3. As the 7th generation, i77700 cannot meet the upgrade needs of win11. 4. However, i77700 is completely capable of using win11 smoothly in terms of performance. 5. So you can use the win11 direct installation system of this site. 6. After the download is complete, right-click the file and "load" it. 7. Double-click to run the "One-click

Can I use Bluetooth headphones in airplane mode? Can I use Bluetooth headphones in airplane mode? Feb 19, 2024 pm 10:56 PM

With the continuous development of modern technology, wireless Bluetooth headsets have become an indispensable part of people's daily lives. The emergence of wireless headphones frees our hands, allowing us to enjoy music, calls and other entertainment activities more freely. However, when we fly, we are often asked to put our phones in airplane mode. So the question is, can I use Bluetooth headphones in airplane mode? In this article, we will explore this question. First, let’s understand what airplane mode does and means. Airplane mode is a special mode for mobile phones

What should I do if win11 cannot use ie11 browser? (win11 cannot use IE browser) What should I do if win11 cannot use ie11 browser? (win11 cannot use IE browser) Feb 10, 2024 am 10:30 AM

More and more users are starting to upgrade the win11 system. Since each user has different usage habits, many users are still using the ie11 browser. So what should I do if the win11 system cannot use the ie browser? Does windows11 still support ie11? Let’s take a look at the solution. Solution to the problem that win11 cannot use the ie11 browser 1. First, right-click the start menu and select "Command Prompt (Administrator)" to open it. 2. After opening, directly enter "Netshwinsockreset" and press Enter to confirm. 3. After confirmation, enter "netshadvfirewallreset&rdqu

How compatible is the Go language on Linux systems? How compatible is the Go language on Linux systems? Mar 22, 2024 am 10:36 AM

The Go language has very good compatibility on Linux systems. It can run seamlessly on various Linux distributions and supports processors of different architectures. This article will introduce the compatibility of Go language on Linux systems and demonstrate its powerful applicability through specific code examples. 1. Install the Go language environment. Installing the Go language environment on a Linux system is very simple. You only need to download the corresponding Go binary package and set the relevant environment variables. Following are the steps to install Go language on Ubuntu system:

WIN10 compatibility lost, steps to recover it WIN10 compatibility lost, steps to recover it Mar 27, 2024 am 11:36 AM

1. Right-click the program and find that the [Compatibility] tab is not found in the properties window that opens. 2. On the Win10 desktop, right-click the Start button in the lower left corner of the desktop and select the [Run] menu item in the pop-up menu. 3. The Win10 run window will open, enter gpedit.msc in the window, and then click the OK button. 4. The Local Group Policy Editor window will open. In the window, click the [Computer Configuration/Administrative Templates/Windows Components] menu item. 5. In the opened Windows component menu, find the [Application Compatibility] menu item, and then find the [Remove Program Compatibility Property Page] setting item in the right window. 6. Right-click the setting item, and in the pop-up menu

Detailed explanation of win11 compatibility issues with win10 software Detailed explanation of win11 compatibility issues with win10 software Jan 05, 2024 am 11:18 AM

The software in the win10 system has been perfectly optimized, but for the latest win11 users, everyone must be curious about whether this system can be supported, so the following is a detailed introduction to the win11 software that does not support win10. Come and find out together. Does win11 support win10 software: 1. Win10 system software and even Win7 system applications are well compatible. 2. According to feedback from experts who use the Win11 system, there are currently no application incompatibility issues. 3. So you can upgrade boldly with confidence, but ordinary users are advised to wait until the official version of Win11 is released before upgrading. 4. Win11 not only has good compatibility, but also has Windo

Introducing the driver download method for win10 to ensure compatibility Introducing the driver download method for win10 to ensure compatibility Jan 01, 2024 pm 06:59 PM

The driver of a hardware device is one of the most important programs for us to use this device normally, but sometimes we may encounter that the driver we download and install is incompatible. In fact, the system can automatically find a compatible driver to download and install. Let’s take a look at it together. Just give it a try. How to make win10 driver compatible? 1. First find this computer on the desktop, right-click and select to open "Properties" 2. Then find and open "Device Manager" on the left 3. Find the device you want to download and install in the device manager, right-click and select "Update driver" 4. Then select "Automatically search for updated driver software" 5. Finally, wait for a while and the following window will pop up, which means the driver installation is complete.

See all articles