


Sorting out some JavaScript compatibility notes for IE and Firefox_javascript skills
(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().
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).

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 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.

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'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.

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 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.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools