Chrome浏览器、火狐等浏览器上和IE类浏览器(360、qq等)有所不同,目前已发现的不同以及解决办法

来源:互联网 发布:三星oculus 软件下载 编辑:程序博客网 时间:2024/04/30 21:42
 1.    Chrome浏览器、火狐等浏览器上和IE类浏览器(360、qq等)有所不同,目前已发现的不同以及解决办法

(1)    IE是parent.document,Chrome是parent.contentDocument

解决办法(通用型):

var doc=parent.document;

if(doc==null) //在Chrome浏览器上parent.document不存在,doc==null

    doc=parent.contentDocument; //赋值Chrome浏览器上可以使用的对应属性

(2)    IE是filter:alpha(opacity=50);Chrome是opacity:0.5;

解决办法(通用型):在控件的style中两个都写上

    style={ filter:alpha(opacity=50); opacity:0.5}  //注意透明度的取值范围是不同的IE是0~100,Chrome是0~1.

代码修改透明度如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">

function SetOpa(obj,value)
{
 var filter=obj.filters;
 if(filter==null) //用于Chrome等浏览器
 {
   obj.style.opacity=value/100.0; //注意透明度取值为0~1之间
 }
 else//用于IE、360等浏览器
 {
  //注意如果定义
  //var opa=obj.filters.alpha.opacity;
  //opa=value透明度设置将无任何效果,必须直接赋值,原因未知
  obj.filters.alpha.opacity=value;//注意透明度取值为0~100之间
 }
}

function SetOpacity()
{
  var obj=document.getElementById("img1");
  SetOpa(obj,50);
}
</script>
<body onload="SetOpacity()">
<img src="light.png" width="128" height="128" id="img1" style="filter:Alpha(Opacity=100);Opacity:1;" />
</body>
</html>