判断浏览器类型及终端来源

由于目前需要判断浏览器类型及终端来源,因此做了一下的总结:

判断浏览器类型:

<!DOCTYPE html>
<html lang="zh-CN">
   <head>
        <meta charset="utf-8">
        <title>判断浏览器类型</title>
   </head>
   <body>
   </body>
       <script language="JavaScript">  
        <!--  
        function getBrowserType()  
        {  
            
            var agent = navigator.userAgent.toLowerCase() ;
            var browserType = '';

           if(agent.indexOf("msie")>0) {  
                   browserType = 'ie';        
           }  
           if(agent.indexOf("firefox")>0){ 
                browserType = 'firefox'; 
           }  
           if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {  
                   browserType = 'safari';
           }
           if(agent.indexOf("chrome")>0){
                   browserType = 'chrome';
           }   
           if(agent.indexOf("opera")>0){
                   browserType = 'opera';
           }
            return browserType;
        }  
         alert("您的浏览器类型为:"+getBrowserType());  
        -->  
    </script> 
</html>

判断终端来源:

  

function getTerminal(){
   var Type = 'pc';//默认为pc端,可取两值:pc,MT(移动端) 
   var terminal = '';//终端标识,值可取iPhone,iPod,Android,iPad
   if( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/iPad/i)) ) { 
       Type = 'MT'; 
    }
   if(navigator.userAgent.match(/iPhone/i)){
     terminal = 'iPhone';
   }
   if(navigator.userAgent.match(/iPod/i)){
     terminal = 'iPod';
   }
   if(navigator.userAgent.match(/Android/i)){
     terminal = 'Android';
   }
   if(navigator.userAgent.match(/iPad/i)){
     terminal = 'iPad'
   }
   return {"Type":Type,"terminal":terminal};
}

参考:http://www.cnblogs.com/wqing/archive/2012/08/13/2636626.html

 

posted @ 2014-09-18 11:45  奋力向前CO  阅读(348)  评论(0编辑  收藏  举报