Home  >  Article  >  Web Front-end  >  Regarding the similarities and differences in page presentation in IE, Firefox and Opera, writing scripts is painful_javascript skills

Regarding the similarities and differences in page presentation in IE, Firefox and Opera, writing scripts is painful_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:47:30879browse

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:




IE&Firefox:



15. 事件委托方法
IE:document.body.onload = inject; //Function inject()在这之前已被实现
Firefox:document.body.onload = inject();
有人说标准是:
document.body.onload=new Function('inject()');



16. firefox与IE(parentElement)的父元素的区别
IE:obj.parentElement
firefox:obj.parentNode
解决方法: 因为firefox与IE都支持DOM,因此使用obj.parentNode是不错选择.
17.cursor:hand VS cursor:pointer
firefox不支持hand,但ie支持pointer
解决方法: 统一使用pointer
18.innerText在IE中能正常工作,但是innerText在FireFox中却不行.
解决方法:
if(navigator.appName.indexOf("Explorer") > -1){
document.getElementById('element').innerText = "my text";
} else{
document.getElementById('element').textContent = "my text";
}

19. FireFox中类似 obj.style.height = imgObj.height 的语句无效
解决方法:
obj.style.height = imgObj.height + 'px';

20. ie,firefox以及其它浏览器对于 table 标签的操作都各不相同,在ie中不允许对table和tr的innerHTML赋值,使用js增加一个tr时,使用appendChile方法也不管用。
解决方法:
//向table追加一个空行:
var row = otable.insertRow(-1);
var cell = document.createElement("td");
cell.innerHTML = " ";
cell.className = "XXXX";
row.appendChild(cell);

21. padding 问题
padding 5px 4px 3px 1px FireFox无法解释简写,
必须改成 padding-top:5px; padding-right:4px; padding-bottom:3px; padding-left:1px;

22. 消除ul、ol等列表的缩进时
样式应写成:list-style:none;margin:0px;padding:0px;
其中margin属性对IE有效,padding属性对FireFox有效
23. CSS透明
IE:filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60)。
FF:opacity:0.6。
24. CSS圆角
IE:不支持圆角。
FF: -moz-border-radius:4px,或者-moz-border-radius-topleft:4px;-moz-border- radius-topright:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius- bottomright:4px;。
25. CSS双线凹凸边框
IE:border:2px outset;。
FF: -moz-border-top-colors: #d4d0c8 white;-moz-border-left-colors: #d4d0c8 white;-moz-border-right-colors:#404040 #808080;-moz-border-bottom-colors:#404040 #808080;
Statement:
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