判断不同浏览器

function isFF(){ //火狐
return window.navigator.userAgent.toLowerCase().indexOf("firefox") >=1
}

function isIE(){ //IE
return window.navigator.userAgent.toLowerCase().indexOf("msie") >=1
}

function isOldIE(){//IE9以下
var version = navigator.appVersion;
version = version.split("MSIE ")[1].split(";");
return parseInt(version) < 9;
}

function isChrome(){ //谷歌
return window.navigator.userAgent.toLowerCase().indexOf("chrome") >=1
}

//为火狐添加innerText属性是出于安全考虑

if(isFF()){ //firefox innerText define
HTMLElement.prototype.__defineGetter__( "innerText",
function(){
var anyString = "";
var childS = this.childNodes;//childNodes 属性,标准的,它返回指定元素的子元素集合,包括HTML节点,所有属性,文本。可以通过nodeType来判断是哪种类型的节点,只有当nodeType==1时才是元素节点,2是属性节点,3是文本节点。
for(var i=0; i <childS.length; i++) {
if(childS[i].nodeType==1)
anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__( "innerText",
function(sText){
this.textContent=sText;
}
);
}

posted @ 2015-07-08 11:27  jiapeng  阅读(158)  评论(0编辑  收藏  举报