码迷,mamicode.com
首页 > 其他好文 > 详细

浏览器判断

时间:2017-03-29 18:32:52      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:safari   cti   sof   window   tle   logs   title   javascrip   gen   

 

 

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus&#174;">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
   
 </body>
 <script>
function getType() {
    var nav = navigator,
        s = nav.userAgent,
        res = unknow; 
 
    if(s.indexOf(Chrome) !== -1) {
        if(nav.languages) {
            //360目前(6.3)不支持webkitPersistentStorage等以webkit开头的属性
            res = Chrome;
        }else {
            res = 360;
        }
    }else if(s.indexOf(Firefox) !== -1) {
        res = Firefox;
    }else if(isIECore()) {
        if(window.__IE_DEVTOOLBAR_CONSOLE_COMMAND_LINE) {
            res = 360;
        }else {
            if(s.indexOf(MSIE) !== -1) {
                res = s.split(;)[1].split(.)[0];
            }else {
                res = MSIE 11;
            }
        }
    }else if(s.indexOf(Opera) !== -1) {
        res = Opera;
    }else if(s.indexOf(Safari) !== -1) {
        res = Safari
    }
 
    return res;
}
function isIECore() {
    var boo = true;
     
    try{
        new ActiveXObject("Microsoft.XMLHTTP");
    }catch(e) {
        boo = false;
    }
    return boo;
}
alert(getType());
 </script>





或者下面的写法


<script language="JavaScript">

<!--

function getOs() {

var OsObject = "";

if(navigator.userAgent.indexOf("MSIE")>0) {

return "MSIE";

}

if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){

return "Firefox";

}

if(isSafari=navigator.userAgent.indexOf("Safari")>0) {

return "Safari";

}

if(isCamino=navigator.userAgent.indexOf("Camino")>0){

return "Camino";

}

if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){

return "Gecko";

}

 

}

alert("您的浏览器类型为:"+getOs());

-->

</script>









</html>

 

浏览器判断

标签:safari   cti   sof   window   tle   logs   title   javascrip   gen   

原文地址:http://www.cnblogs.com/jinsuo/p/6641160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!