Home > Article > Web Front-end > Regarding the similarities and differences in page presentation in IE, Firefox and Opera, writing scripts is painful_javascript skills
1.document.formName.item("itemName") Problem
Description: Under IE, you can use document.formName.item("itemName") or document.formName.elements ["elementName"]; under Firefox, you can only use Use document.formName.elements["elementName"].
Solution: Use document.formName.elements["elementName"] uniformly.
2. Collection class object problem
Explanation: Under IE, it can be used () or [] to obtain collection objects; under Firefox, you can only use [] to obtain collection objects.
Solution: Use [] uniformly to obtain collection objects.
3. Custom attribute issues
Note: 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 get custom attributes.
Solution: Unification Get custom attributes through getAttribute().
4.eval("idName") problem
Explanation: 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 the id idName.
Solution: Use getElementById("idName") uniformly to obtain the HTML object with the id idName.
5. The problem that the variable name is the same as the ID of an HTML object
Note: Under IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document; it cannot be used under Firefox. Under Firefox, the ID of the HTML object can be used as the same as the HTML object ID. variable name; this is not possible 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; always add var when declaring variables to avoid ambiguity.
6.const problem
Explanation: 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 var uniformly Keywords to define constants.
7.Input.type attribute problem
Explanation: The input.type attribute under IE is read-only; but the input.type attribute under Firefox is read-write.
8.window.event Problem
Description: window.event can only be run under IE, not Firefox. This is because Firefox's event can only be used at the scene where the event occurs.
Solution:
IE:
...
IE&Firefox:
...
9.event.x and event .y problem
Explanation: Under IE, the even object has x, y attributes, but no pageX, pageY attributes; under Firefox, the even object has pageX, pageY attributes, but no x, y attributes.
Solution: Use mX (mX = event.x ? event.x : event.pageX;) to replace event.x under IE or event.pageX under Firefox.
10.event.srcElement problem
Explanation: Under IE , the even object has the srcElement attribute, but no target attribute; under Firefox, the even object has the target attribute, but does not have the srcElement attribute.
Solution: use obj (obj = event.srcElement ? event.srcElement : event.target;) To replace event.srcElement under IE or event.target under Firefox.
11.window.location.href problem
Explanation: Under IE or Firefox2.0.x, you can use window.location or window.location .href; Under Firefox 1.5.x, only window.location can be used.
Solution: Use window.location instead of window.location.href.
12. Modal and non-modal window issues
Note: Under IE, modal and non-modal windows can be opened through showModalDialog and showModelessDialog; but not under Firefox.
Solution: Directly use window.open(pageURL, name, parameters) 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. For example: var parWin = window.opener; parWin.document.getElementById("Aqing"). value = "Aqing";
13.Frame problemTake the following frame as an example:
(1) Access the frame object:
IE: Use window.frameId or window .frameName to access this frame object.
Firefox: You can only use window.frameName to access this frame object.
In addition, you can use window.document.getElementById("frameId") to access it in both IE and Firefox. This frame object.
(2) Switch frame content: You can use window.document.getElementById("testFrame").src = "xxx.html" or window.frameName.location = in both IE and Firefox "xxx.html" to switch the content of the frame. If you need to pass the parameters in the frame back to the parent window, you can use parent in frme to access the parent window.例如:parent.document.form1.filename.value="Aqing";
14.body问题
Firefox的body在body标签没有被浏览器完全读入之前就存在;而IE的body则必须在body标签被浏览器完全读入之后才存在.
例如:
Firefox: