Heim  >  Artikel  >  Web-Frontend  >  js判断浏览器的比较全的代码_基础知识

js判断浏览器的比较全的代码_基础知识

WBOY
WBOYOriginal
2016-05-16 19:19:24866Durchsuche

现在的浏览器可真是越来越多,但兼容性可真是不敢恭维,这个脚本可根据浏览器 来自动进行导航,在特定场合是非常有用的,你好好看看吧!!!

复制代码 代码如下:

<script> <BR><!-- <BR>function browserSniffer(netscape4URL,explorer4URL,webtvURL, <BR>aolURL,operaURL,version3URL,w3cURL) { <BR>var agt=navigator.userAgent.toLowerCase(); <BR>var agt=navigator.userAgent.toLowerCase(); <BR>var is_major = parseInt(navigator.appVersion); <BR>var is_minor = parseFloat(navigator.appVersion); <BR>var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) <BR>&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) <BR>&& (agt.indexOf('webtv')==-1)); <BR>var is_nav2 = (is_nav && (is_major == 2)); <BR>var is_nav3 = (is_nav && (is_major == 3)); <BR>var is_nav4 = (is_nav && (is_major == 4)); <BR>var is_nav4up = (is_nav && (is_major >= 4)); <BR>var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || <BR>(agt.indexOf("; nav") != -1)) ); <BR>var is_nav5 = (is_nav && (is_major == 5)); <BR>var is_nav5up = (is_nav && (is_major >= 5)); <BR>var is_ie = (agt.indexOf("msie") != -1); <BR>var is_ie3 = (is_ie && (is_major < 4)); <BR>var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) ); <BR>var is_ie4up = (is_ie && (is_major >= 4)); <BR>var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ); <BR>var is_ie5up = (is_ie && !is_ie3 && !is_ie4); <BR>var is_aol = (agt.indexOf("aol") != -1); <BR>var is_aol3 = (is_aol && is_ie3); <BR>var is_aol4 = (is_aol && is_ie4); <BR>var is_opera = (agt.indexOf("opera") != -1); <BR>var is_webtv = (agt.indexOf("webtv") != -1); <BR>if (is_nav4up) { <BR>location.href = netscape4URL; // netscape 4+ but not NS5 <BR>}else if (is_ie4up) { //IE4 & IE5 but returns IE4 <BR>location.href = explorer4URL; <BR>}else if (is_webtv) { // Web TV <BR>location.href = webtvURL; <BR>}else if (is_aol || is_aol3 || is_aol4) { //AOL <BR>location.href = aolURL; <BR>}else if (is_opera) { // Opera <BR>location.href = operaURL; <BR>}else if (is_ie3||is_nav3) { // 3.0 version browsers <BR>location.href = version3URL; <BR>}else if (is_nav5up) { // Netscape 5 <BR>location.href = w3cURL; <BR>} <BR>} <BR>//--> <BR></script>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn