判断浏览器navigator.appName == "Microsoft Internet Explorer"
navigator.userAgent.indexOf("MSIE")>0
ff不支持
window.close()
innerText textContent
ff只有在window.open()的情况下支持window.close();但如果这个页是iframe也不行,建议用top.close.
children不支持,支持childNodes
ff读xml也要注意IE里面01234子节点,ff里面就变成13579了
IE
var opname=c.childNodes[0].text;
var opid=c.childNodes[1].text;
var opurl=c.childNodes[2].text;
var opuser=c.childNodes[3].text;
var opadress=c.childNodes[4].text
ff
var opname=c.childNodes[1].textContent;
var opid=c.childNodes[3].textContent;
var opurl=c.childNodes[5].textContent;
var opuser=c.childNodes[7].textContent;
var opadress=c.childNodes[9].textContent;
在mf中,自己定义的属性必须getAttribute()取得
但是千万注意,getAttribute()取得的值是不会变的,比如
var a=b.getAttribute("属性")
b.属性=100
var c=b.getAttribute("属性")
不管b.属性改成多少,a和c是相等的。
建议操作方式
全局变量 fag=0;
if(fag==0)
fag=b.属性=b.getAttribute("属性");
ff不能写function a.b()
{}
要写成a.b=function(){}
ff不支持src="file:///c:a.gif";
xmlHttp.setRequestHeader ff里面一定要大写
ff的ajax,IE里面可以有很多写法,但ff里面有时就会出错,下面写一种不会出错的写法
function GetDataFromServer( url, id )
{
if(window.XMLHttpRequest)
{ request = new XMLHttpRequest();}
else
if(window.ActiveXObject)
{ request = new ActiveXObject("MSXML2.XMLHTTP.5.0");}
var serverUrl = url ;
if( request )
{
window.status = "数据更新中...." ;
request.open("get",serverUrl,true) ;
request.setRequestHeader("content-type","application/x-www-form-urlencoded") ;
request.onreadystatechange = function(){onResponse(id);};
request.send(null) ;
}
}
function onResponse(id)
{
var xmlHttp=request;
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var result = xmlHttp.responseText ;
if(document.getElementById("load_"+id))
{
逻辑;
}
window.status = "数据更新完成" ;
}
}
}
同时支持IE和Firefox的日期控件---DatePicker
ie parentElement
ff parentNode
IE支持insertAdjacentElement,insertAdjacentHTML,insertAdjacentText
FF要实现
//--- 支持moz -------------------------------------------------------
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
switch (where)
{
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this);
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if(this.nextSibling)
{
this.parentNode.insertBefore(parsedNode,this.nextSibling);
}
else
{
this.parentNode.appendChild(parsedNode);
}
break;
}
}
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML);
}
HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{
var parsedText = document.createTextNode(txtStr);
this.insertAdjacentElement(where,parsedText);
}
}
attachEvent方法,为某一事件附加其它的处理事件。(不支持Mozilla系列)
addEventListener方法 用于 Mozilla系列
举例:
document.getElementById("btn").onclick = method1;
document.getElementById("btn").onclick = method2;
document.getElementById("btn").onclick = method3;
如果这样写,那么将会只有medhot3被执行
写成这样:
var btn1Obj = document.getElementById("btn1");
//object.attachEvent(event,function);
btn1Obj.attachEvent("onclick",method1);
btn1Obj.attachEvent("onclick",method2);
btn1Obj.attachEvent("onclick",method3);
执行顺序为method3->method2->method1
如果是Mozilla系列,并不支持该方法,需要用到addEventListener
var btn1Obj = document.getElementById("btn1");
//element.addEventListener(type,listener,useCapture);
btn1Obj.addEventListener("click",method1,false);
btn1Obj.addEventListener("click",method2,false);
btn1Obj.addEventListener("click",method3,false);
执行顺序为method1->method2->method3
火狐和ie通用的event写法
<script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> function getEvent() //同时兼容ie和ff的写法
{
if(document.all) return window.event;
func=getEvent.caller;
while(func!=null){
var arg0=func.arguments[0];
if(arg0)
{
if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
{
return arg0;
}
}
func=func.caller;
}
return null;
}
如调用:function test() {
var event=getEvent();
if (navigator.appName=='Microsoft Internet Explorer') {
alert(event.x);
}else if (navigator.appName=='Netscape') {
alert(event.pageX);
}
<script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> <script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> <script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> <script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> <script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script> <script type="text/javascript"> function getEvent() //同时兼容ie和ff的写法 { if(document.all) return window.event; func=getEvent.caller; while(func!=null){ var arg0=func.arguments[0]; if(arg0) { if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func=func.caller; } return null; } function test() { var event=getEvent(); if (navigator.appName=='Microsoft Internet Explorer') { alert(event.x); } else if (navigator.appName=='Netscape') { alert(event.pageX); } } </script>