各浏览器的JS兼容问题

Posted on 2007-05-23 22:37 sunbaby 阅读(787) 评论(0)  编辑  收藏 所属分类: 其它
ie/firefox:禁止选择文字

IE:

<script>
document.onselectstart 
= function(){return false;}
</script>
<body>
试试看能否选择这些文字?
</body>

FF:

<style>
html 
*{-moz-user-select: none;}
</style>
<body>
试试看能否选择这些文字?
</body> 

 

关于currentStyle兼容

IE Only:
<style>
#test
{width:100px;background-color:red;}
</style>
<script>
window.onload
=function(){
var t=document.getElementById('test')
var ts=t.currentStyle;
t.innerHTML
=
"t.style.width:"+ts.width+"<br />"+
"t.style.backgroundColor:"+ts.backgroundColor+"<br />"+
"t.style.color:"+ts.color+"<br />"+
"t.style.paddingLeft:"+ts.paddingLeft
}

</script>
<body>
<div id="test" style="color:yellow;padding-left:100px;">
</div>
</body>

FF Only:
<style>
#test
{width:100px;background-color:red;}
</style>
<script>
window.onload
=function(){
var t=document.getElementById('test')
var ts=document.defaultView.getComputedStyle(t, null);
t.innerHTML
=
"t.style.width:"+ts.width+"<br />"+
"t.style.backgroundColor:"+ts.backgroundColor+"<br />"+
"t.style.color:"+ts.color+"<br />"+
"t.style.paddingLeft:"+ts.paddingLeft
}

</script>
<body>
<div id="test" style="color:yellow;padding-left:100px;">
</div>
</body>

 

 

IE Mozilla 说明
document.body.clientHeight(clientWidth)根据HTMLDTD而定方能得到准确值。 window.innerHeight(innerWidth)根据HTMLDTD而定方能得到准确值。  
opacity(aplha=20) MozOpacity="0.2"  
event.clientY(clientX) event.pageY(pageX)  
event.keyCode event.which  
event.srcElement event.target  
window.external.AddFavorite('never-online.net', "never-online'website"); window.sidebar.addPanel('never-online.net', "never-online'website", ""); 此为添加到收藏夹代码,要兼容更多浏览器,请看这里代码
(DHTML事件-滚轮事件)onmousewheel DOMMouseScroll 可参看我blog这篇文章
window.showModalDialog window.open(url, "name", "modal=yes")  
createPopup() xul  
htc控件 xbl绑定  
filter滤镜 只支持alpha(透明度,部分可通过clip来模拟)  
obj.setCapture() window.captureEvents(Event.eventType)  
obj.attachEvent(type, listener) obj.addEventListener(type, listener, useCapture) 添加事件方法,如果要兼容,有几种方法,如用Mozilla读写器来模拟IE方法,或者用一个全局函数addEvent(type, listener, useCapture)来统一事件处理,或者写一个Event Manager更好一些,也可以在这里统一避免内存泄露
obj.detachEvent(type, listener) obj.removeEventListener(type, listener, useCapture) 一般情况下,用了attachEvent(addEventListener)方法,最好在beforeunload事件里用detach方法释放掉,这是个好习惯(偷懒话就不说了:D)
支持Webdings字体 不支持Webdings字体  
insertAdjacentHTML, insertAdjacentElement方法 本身不支持,但可通过insertBefore或通过Range实现  
不支持 读写器__defineSetter(Getter)__  
不支持 支持对Element,EVENT等对象prototype模式支持  
不支持 对节点有nodeType常量属性  
new ActiveXObject("MSXML2.XMLHTTP")或更高版本ProgId XMLHttpRequest对象  
设置类似style.top=20这样高度时,可不使用单位 设置类似style.top=20+'px'这样高度时,必须使用单位,否则无效  
CSS类名,不区分大小写(大小写不敏感) CSS类名,区分大小写(大小写敏感)如:.myCss和.mycss类名就是不相同  
冒泡事件event.cancelBubble=true event.stopPropagation()(需要传递event事件)  
CSS padding宽度并不在offset偏移坐标之内 CSS padding宽度默认是在offset偏移坐标之内,可用-moz-box-sizing:border-box来设置即可基本与IE相同 可参见我这篇文章代码
js动态加载xslt文件将xml转化成HTML,IE可用xmldoc.transformNode(xslDocument)方法 Mozilla相对麻烦一些,要经过几道工序XSLTProcessor对象,transformToFragment或其它方法 可参见我这篇文章示例教程和代码
持客户端存储数据-userData 不支持

posts - 2, comments - 2, trackbacks - 0, articles - 25

Copyright © sunbaby

free web counter
free web counter 点击发送消息给我