zoukankan      html  css  js  c++  java
  • 判断浏览器类型及终端来源

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

    判断浏览器类型:

    <!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

  • 相关阅读:
    申通服务恶劣,开始忘本
    基础知识学习外部排序
    ToString()格式和用法大全
    Web.Config Transformation ASP.NET 4.0 新特性
    拒绝try.catch泛滥,学习委托有感
    Oracle Job定时任务的使用详解
    数据库和索引设计简要笔记
    Redis实际应用场景
    线程如何按照自己指定的顺序执行
    WCF 4.0 进阶系列 随笔汇总
  • 原文地址:https://www.cnblogs.com/hanbingljw/p/3978912.html
Copyright © 2011-2022 走看看