zoukankan      html  css  js  c++  java
  • js判断用户的浏览器

     

    1,判断pc和移动端

     function browserRedirect() {
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
        var bIsMidp = sUserAgent.match(/midp/i) == "midp";
        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
        var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
        var bIsAndroid = sUserAgent.match(/android/i) == "android";
        var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
        var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
        document.writeln("您的浏览设备为:");
        if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
               document.writeln("phone");
         } else {
             document.writeln("pc");
         }
    }
    
    browserRedirect();
    

     

    2,判断安卓和ios

    $(function(){
        var ua = navigator.userAgent.toLowerCase();
        if (/iphone|ipad|ipod/.test(ua)) {
          $("a").attr("href","https://itunes.apple.com/us/app/ren-ren-duo-bao-yi-ge-shou/id1111430715?l=zh&ls=1&mt=8"); 
        } else {
              $("a").attr("href","http://www.rrdb8.com/statics/templates/app/RenRenDuoBao.apk"); 
        }
    })
    

    3,判断pc浏览器

     <script type="text/javascript">
            var Sys = {};
            var ua = navigator.userAgent.toLowerCase();
            if (window.ActiveXObject)
                Sys.ie = ua.match(/msie ([\d.]+)/)[1]
            else if (document.getBoxObjectFor)
                Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
            else if (window.MessageEvent && !document.getBoxObjectFor)
                Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]
            else if (window.opera)
                Sys.opera = ua.match(/opera.([\d.]+)/)[1]
            else if (window.openDatabase)
                Sys.safari = ua.match(/version\/([\d.]+)/)[1];
            
            //以下进行测试
            if(Sys.ie) document.write('IE: '+Sys.ie);
            if(Sys.firefox) document.write('Firefox: '+Sys.firefox);
            if(Sys.chrome) document.write('Chrome: '+Sys.chrome);
            if(Sys.opera) document.write('Opera: '+Sys.opera);
            if(Sys.safari) document.write('Safari: '+Sys.safari);
        </script>

      

  • 相关阅读:
    centos下卸载rpm包
    centos下添加环境变量和启动apache
    centos(linux) 下如何查看端口占用情况及杀死进程
    如何使上层的div遮住的链接可以点击
    jquery.blockUI.2.31.js 弹出层项目介绍
    fieldset、legend、display html元素
    <a>标签中href="javascript:;"的意思
    memcache 学习笔记
    sublime text3 JS语法检测插件
    Apache Rewrite的主要功能
  • 原文地址:https://www.cnblogs.com/tkzc2013/p/6015212.html
Copyright © 2011-2022 走看看