IE6 IE 7 Firefox兼容处理
来源:互联网 发布:it项目管理工具 编辑:程序博客网 时间:2024/05/29 06:47
1. event.srcElement 属性:
IE下可以使用event.srcElement属性,但在Firefox下只有target属性,所以要兼容两者需使用:
var el = evt.srcElement ? evt.srcElement : evt.target;
2. document.all 属性:
在IE下可以引用document.all属性获取所有dom内容,但在firefox下只能使用
document.getElementsByTagName("*")
3."event is not defined" FireFox event 問題處理:
var y = evt.clientY; // 取得滑鼠指標目前的 y 位置
4. IE6和IE7在display:block的区别:
IE6 对 A标签 的 display:block 解释有误,会对block属性失效,具体的解决办法是将a标签加上一个固定的高度,如下:
* {
margin:0px;
padding:0px;
border:none;
}
ul {
width:100px;
font: 12px Verdana;
}
li{
width:100%;
height:20px;
background-color:#CCCCCC;
margin:2px 10px;
}
li a{
display:block;
width:100%;//加上这两句
height:100%;//加上这两句
text-decoration:none;
}
li a:hover{
background-color:#999999;
}
-->
</style>
</head>
<body>
<ul>
<li><a href="#">aaaaaa</a></li>
<li><a href="#">bbbbbb</a></li>
<li><a href="#">cccccc</a></li>
<li><a href="#">dddddd</a></li>
<li><a href="#">eeeeee</a></li>
<li><a href="#">ffffff</a></li>
</ul>
</body>
</html>
5. InnerText的区别:Firefox不支持InnerText需要用textContent代替:
<script language="javascript">
function faa(){
if(document.all){aa.innerText="11111"}else{aa.textContent="11111";}
}
</script>
<font id="aa">0000</font><input type="button" onclick="faa()">
6.event.keyCode 和event.which
FF不支持window.event.keyCode,代替着是event.which
列子:
//在网页上面屏蔽tab键的代码
document.onkeydown = function (e){
var theEvent = window.event || e;
var code = theEvent.keyCode || theEvent.which;
if(code == 9){
return false;
}
}
转载:
1.document.formName.item("itemName") 问题
说明:
IE下,可以使用document.formName.item("itemName")或document.formName.elements["elementName"];
Firefox下,只能使用document.formName.elements["elementName"].
解决方法:
统一使用document.formName.elements["elementName"].
Text1:
document.formName.item("itemName")
document.formName.elements["elementName"]
-------------------------------------------------
2.集合类对象问题
说明:
IE下,可以使用()或[]获取集合类对象;
Firefox下,只能使用[]获取集合类对象.
解决方法:
统一使用[]获取集合类对象.
Text2:
document.forms("formName")
document.forms["formName"]
Text3:
document.getElementsByName("inputName")(0)
document.getElementsByName("inputName")[0]
-------------------------------------------------
3.自定义属性问题
说明:
IE下,可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性;
Firefox下,只能使用getAttribute()获取自定义属性.
解决方法:
统一通过getAttribute()获取自定义属性.
Text4:
直接获取自定义属性的值
通过getAttribute()获取自定义属性的值
-------------------------------------------------
4.eval("idName")问题
说明:
IE下,可以使用eval("idName")或getElementById("idName")来取得id为idName的HTML对象;
Firefox下只能使用getElementById("idName")来取得id为idName的HTML对象.
解决方法:
统一用getElementById("idName")来取得id为idName的HTML对象.
Text5:
eval("idName")
document.getElementById("itemId")
-------------------------------------------------
5.变量名与某HTML对象ID相同的问题
说明:
IE下,HTML对象的ID可以作为document的下属对象变量名直接使用;
Firefox下则不能.
Firefox下,可以使用与HTML对象ID相同的变量名;
IE下则不能。
解决方法:
使用document.getElementById("idName")代替document.idName.最好不要取HTML对象ID相同的变量名,以减少错误;在声明变量时,一律加上var,以避免歧义.
-------------------------------------------------
6.const问题
说明:
Firefox下,可以使用const关键字或var关键字来定义常量;
IE下,只能使用var关键字来定义常量.
解决方法:
统一使用var关键字来定义常量.
-------------------------------------------------
7.input.type属性问题
说明:
IE下input.type属性为只读;但是Firefox下input.type属性为读写.
-------------------------------------------------
8.window.event问题
说明:
window.event只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用.
解决方法:
IE:
<input name="Button8_1" type="button" value="IE" />
...
<script language="javascript">
function gotoSubmit8_1() {
...
alert(window.event); //use window.event
...
}
</script>
IE&Firefox:
<input name="Button8_2" type="button" value="IE" />
...
<script language="javascript">
function gotoSubmit8_2(evt) {
...
evt=evt?evt:(window.event?window.event:null);
alert(evt); //use evt
...
}
</script>
-------------------------------------------------
9.event.x与event.y问题
说明:
IE下,even对象有x,y属性,但是没有pageX,pageY属性;
Firefox下,even对象有pageX,pageY属性,但是没有x,y属性.
解决方法:
使用mX(mX = event.x ? event.x : event.pageX;)来代替IE下的event.x或者Firefox下的event.pageX.
-------------------------------------------------
10.event.srcElement问题
说明:
IE下,even对象有srcElement属性,但是没有target属性;
Firefox下,even对象有target属性,但是没有srcElement属性.
解决方法:
使用obj(obj = event.srcElement ? event.srcElement : event.target;)来代替IE下的event.srcElement或者Firefox下的event.target.
-------------------------------------------------
11.window.location.href问题
说明:
IE或者Firefox2.0.x下,可以使用window.location或window.location.href;
Firefox1.5.x下,只能使用window.location.
解决方法
:使用window.location来代替window.location.href.
-------------------------------------------------
12.模态和非模态窗口问题
说明:
IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;
Firefox下则不能.
解决方法:
直接使用window.open(pageURL,name,parameters)方式打开新窗口。
如果需要将子窗口中的参数传递回父窗口,可以在子窗口中使用window.opener来访问父窗口.
例如:var parWin = window.opener; parWin.document.getElementById("Aqing").value = "Aqing";
-------------------------------------------------
13.frame问题
以下面的frame为例:
<frame src="xxx.html" id="frameId" name="frameName" />
(1)访问frame对象:
IE:使用window.frameId或者window.frameName来访问这个frame对象.
Firefox:只能使用window.frameName来访问这个frame对象.
另外,在IE和Firefox中都可以使用window.document.getElementById("frameId")来访问这个frame对象.
(2)切换frame内容:
在IE和Firefox中都可以使用window.document.getElementById("testFrame").src ="xxx.html"或window.frameName.location = "xxx.html"来切换frame的内容.
如果需要将frame中的参数传回父窗口,可以在frme中使用parent来访问父窗口。例如:parent.document.form1.filename.value="Aqing";
-------------------------------------------------
14.body问题
Firefox的body在body标签没有被浏览器完全读入之前就存在;
而IE的body则必须在body标签被浏览器完全读入之后才存在.
例如:
Firefox:
<body>
<script type="text/javascript">
document.body.onclick = function(evt){
evt = evt || window.event;
alert(evt);
}
</script>
</body>
IE&Firefox:
<body>
</body>
<script type="text/javascript">
document.body.onclick = function(evt){
evt = evt || window.event;
alert(evt);
}
</script>
15. IE Firefox Margin Padding :
具体的做法有以下几种:
第一种:
.div {
background:orange;/*ff*/
*background:green !important;/*ie7*/
*background:blue; /*ie6*/
}
第二种:
.div {
margin:10px;/*ff*/
*margin:15px;/*ie7*/
_margin:15px;/*ie6*/
}
第三种:
#div { color: #333; } /* ff */
* html #div { color: #666; } /* IE6 */
*+html #div { color: #999; } /* IE7 */
现在常用了第一种,很好用,写出来与大家分享。
在给一个例子:
#pages{margin:auto; width:910px; text-align:left; }
#pages{*width:915px !important;} /* IE7 */
- IE6 IE 7 Firefox兼容处理
- IE6,IE7和FireFox兼容处理
- IE6,IE7和FireFox兼容处理
- css ie6,7,8,firefox兼容解决方法
- IE6,IE7和FireFox兼容处理(持续发现中)
- firefox与ie兼容
- 兼容 ie firefox offsetX
- 调色板,兼容ie firefox
- 书写同时兼容IE和FireFox的事件处理代码
- 兼容linux firefox和windows ie的xml处理代码
- 兼容IE、FireFox、Chrome等浏览器的xml处理函数
- CSS兼容IE6,IE7,FireFox
- CSS兼容IE6,IE7,FireFox
- js图片滚动代码(IE6/7/8及Firefox兼容)
- 兼容IE6 7 8 chrome firefox图片水平垂直居中
- 让IE支持placeholder属性,兼容IE6,7,8,9
- IE、firefox的js兼容
- CSS兼容IE/Firefox要点
- html5 progress
- Jakarta Commons
- os.popen
- COM编程入门-- 第二部分——深入COM服务器
- 学习编程技术的成长之路
- IE6 IE 7 Firefox兼容处理
- eclispe override报错的解决办法
- spi读ic识别lcd
- sliverlight中数据验证(14)
- gallery3d 代码分析
- COM编程入门--- 第一部分——什么是COM,如何使用COM
- [C/C++]诡异的fread,feof?
- 旅图,去哪儿的Instagram实验
- PLSQL Developer使用、设置及快捷键设置