SoFunction
Updated on 2025-04-07

IE and Firefox compatibility compilation for Javascript

The following is to replace Internet Explorer with IE and MF with Mozilla Firefox

1. Problem
(1) Existing problems:
There are many statements like ("itemName") in the existing code that cannot be run under MF
(2) Solution:
Use ["elementName" instead]
(3) Others
See 2

2. Collection object problem
(1) Existing problems:
Many collection class objects in existing code are used when using (), which IE can accept, but MF cannot.
(2) Solution:
Use [] instead as the subscript operation. For example: ("formName") is changed to ["formName"].
For example: ("inputName")(1) is changed to ("inputName")[1]
(3) Others

3.
(1) Existing problems:
Use Cannot run on MF
(2) Solution:
MF's event can only be used at the scene where the event occurs, and this problem cannot be solved for the time being. This can be done:
Original code (can be run in IE):
<input type="button" name="someButton" value="Submit" onclick="javascript:gotoSubmit()"/>
            ...
            <script language="javascript">
                function gotoSubmit() {
                    ...
                    alert();    // use
                    ...
                }
            </script>

New code (can be run in IE and MF):
<input type="button" name="someButton" value="submit" onclick="javascript:gotoSubmit(event)"/>
            ...
            <script language="javascript">
                function gotoSubmit(evt) {
                    evt = evt ? evt : ( ? : null);
                    ...
                    alert(evt);             // use evt
                    ...
                }
            </script>
In addition, if the first line in the new code remains unchanged, just like the old code (i.e. the gotoSubmit call does not give parameters), it can still be run in IE, but there will be no errors. Therefore, the tpl part of this solution is still compatible with the old code.

4. Issue with the id of HTML object as object name
(1) Existing problems
In IE, the ID of the HTML object can be used directly as the variable name of the object subordinate to the document. Not available in MF.
(2) Solution
Use getElementById("idName") instead of idName as an object variable.

5. The problem of getting the object with the idName string
(1) Existing problems
In IE, using eval(idName) can obtain an HTML object with id as idName, which cannot be used in MF.
(2) Solution
Use getElementById(idName) instead of eval(idName).

6. Problem with the same variable name as the id of a certain HTML object
(1) Existing problems
In MF, because the object id is not the name of the HTML object, you can use the same variable name as the HTML object id, which cannot be used in IE.
(2) Solution
When declaring variables, all 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. With the problem
(1) Existing problems
In IE, the event object has x, y attributes, but not in MF.
(2) Solution
In MF, the equivalent is . But not in IE.
Therefore, use instead. This variable is also available in IE.
There is a subtle difference from   (When there are scroll bars throughout the page), but most of the time it is equivalent.

If you want to be exactly the same, you can be a little more troublesome:
        mX = ? : ;
Then use mX instead
(3) Others
It is both in IE and MF, and whether there is any difference in specific meanings has not been tested.


8. About frame
(1) Existing problems
In IE, you can use this frame, but not in mf
(2) Solution
The most important difference between mf and ie in the use of frame is:
If the following attributes are written in the frame tag:
<frame src="" name="frameName" />
Then ie can access the window object corresponding to this frame through id or name
mf can only access the window object corresponding to this frame through name
For example, if the above frame tag is written in the htm in the uppermost window, then you can access it like this
ie: Or visit this window object
mf: This is the only way to access this window object

In addition, both mf and ie can be used ("frameId") to access frame tags
And you can switch the content of the frame by ("testFrame").src = ''
You can also switch the content of the frame by = ''
For descriptions of frame and window, please refer to bbs' article 'window and frame'
And the test below the /test/js/test_frame/ directory
----adun 2004.12.09 Modified

9. In mf, the attributes defined by yourself must be obtained by getAttribute().
10. Use without parentElement in mf
               parentNode
The meaning of childNodes subscript is different in IE and MF. MF uses the DOM specification, and blank text nodes will be inserted in childNodes.
This problem can generally be avoided by ().
When nodes in html are missing, IE and MF interpret parentNode differently, for example
   <form>
   <table>
        <input/>
   </table>
   </form>
The value in MF is form, while the value in IE is an empty node

Nodes in MF do not have a removeNode method, so the following method (node) must be used.

question
(1) Existing problems:
The const keyword cannot be used in IE. For example, const constVar = 32; in IE this is a syntax error.
(2) Solution:
Don't use const, use var instead.

12. Body object
The body of MF exists before the body tag is fully read in by the browser, while IE must exist after the body is fully read in.

13. url encoding
If you write url in js, just write it directly & don't write it&amp;For example, var url = '?objectName=xx&amp;objectEvent=xxx';
= url, then it is very likely that the url will not be displayed normally so that the parameters are not correctly passed to the server.
Generally, the server will report an error parameter but not found
Of course, if it is an exception in tpl, because tpl complies with the XML specifications, it is required to be written as &amp;
Generally, MF cannot recognize &amp in js;


14. NodeName and tagName issues
(1) Existing problems:
In MF, all nodes have nodeName values, but textNode does not have tagName values. In IE, nodeName is used as if it is used.
There is a problem (the specific situation has not been tested, but my IE has died several times).
(2) Solution:
Use tagName, but you should check whether it is empty.

15. Element properties
Under IE, the attribute is read-only, but it can be modified under MF.


16. Issues with () and [name]
(1) Existing problems:
In IE, getElementsByName() and [name] cannot be used to obtain div elements (it is not known whether there are other elements that cannot be taken).