js判断浏览器的代码
来源:爱站网时间:2019-04-02编辑:网友分享
现在浏览器真的越来越多,但是兼容性真的不是免费的,下文脚本可以根据浏览器自动导航,在特定的场合很有用,感兴趣的小伙伴们可以跟着爱站技术频道小编来学习一下!
现在浏览器真的越来越多,但是兼容性真的不是免费的,下文脚本可以根据浏览器自动导航,在特定的场合很有用,感兴趣的小伙伴们可以跟着爱站技术频道小编来学习一下!
<SCRIPT language="JavaScript">
<!--
function browserSniffer(netscape4URL,explorer4URL,webtvURL,
aolURL,operaURL,version3URL,w3cURL) {
var agt=navigator.userAgent.toLowerCase();
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
(agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));
var is_ie = (agt.indexOf("msie") != -1);
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_aol = (agt.indexOf("aol") != -1);
var is_aol3 = (is_aol && is_ie3);
var is_aol4 = (is_aol && is_ie4);
var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);
if (is_nav4up) {
location.href = netscape4URL; // netscape 4+ but not NS5
}else if (is_ie4up) { //IE4 & IE5 but returns IE4
location.href = explorer4URL;
}else if (is_webtv) { // Web TV
location.href = webtvURL;
}else if (is_aol || is_aol3 || is_aol4) { //AOL
location.href = aolURL;
}else if (is_opera) { // Opera
location.href = operaURL;
}else if (is_ie3||is_nav3) { // 3.0 version browsers
location.href = version3URL;
}else if (is_nav5up) { // Netscape 5
location.href = w3cURL;
}
}
//-->
</SCRIPT>
<BODY >
通过爱站技术频道小编介绍的js判断浏览器的代码,相信大家都有了一定的了解,如需了解更多的相关资讯,请继续关注爱站技术频道吧!