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

  • 相关阅读:
    nuxt使用pdfjs-dist插件实现pdf预览
    package.json详细介绍
    encodeURI()和encodeURIComponent() 区别
    前端预览pdf——文件流
    fatal: unable to access 'https://github.com/xxxxx/xxxx.git/': Failed to connect to github.com port 443: Timed out
    vue分隔输入验证码
    Vue简单实现滚动到底部加载数据
    nuxt pdf在线预览
    Eclipse入门-HelloWorld
    多任务学习算法综述
  • 原文地址:https://www.cnblogs.com/hanbingljw/p/3978912.html
Copyright © 2011-2022 走看看