SoFunction
Updated on 2025-04-14

Analysis of Javascript multiple browser compatibility writing methods page 2/3


1. Problem
(1) Existing problems:
There are many statements like ("itemName") in 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:
Cannot run on MF using
(2) Solution:
MF's event can only be used at the scene where the event occurs, and this problem cannot be resolved 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 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 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.
Also, it is best not to take the same variable name as the HTML object id to reduce errors.
(3) Others
See Question 4
Previous page123Next pageRead the full text