zoukankan      html  css  js  c++  java
  • js对于客户端的区分代码

    //区分设备
    function judge_decice()
    {
        let ua =navigator.userAgent.toLowerCase();
        if(/android|adr/gi.test(ua)) {
            return 'android';
        }else if( /(i[^;]+;( U;)? CPU.+Mac OS X/gi.test(ua)) {
            return 'iphone';
        }else if(/iPad/gi.test(ua)) {
            return 'ipad';
        }else{
            return  'unknow device';
        }
    }
    //判断是不是pc
    function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
                    "SymbianOS", "Windows Phone",
                    "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                 break;
             }
         }
         return flag;
     }
    
    //区分客户端  新浪微博为1,QQ客户端为2,微信低于6.0.2版本为3,高于6.0.2版本为4,其他为0。
    function judge_client()
    {
        var ua = navigator.userAgent.toLowerCase();
        if(ua.match(/weibo/i) == "weibo"){
            console.log(1);
        }else if(ua.indexOf('qq/')!= -1){
            console.log(2);
        }else if(ua.match(/MicroMessenger/i)=="micromessenger"){
            var v_weixin = ua.split('micromessenger')[1];
            v_weixin = v_weixin.substring(1,6);
            v_weixin = v_weixin.split(' ')[0];
            if(v_weixin.split('.').length == 2){
                v_weixin = v_weixin + '.0';
            }
            if(v_weixin < '6.0.2'){
                console.log(3);
            }else{
                console.log(4);
            }
        }else{
            console.log(0);
        }
    
    }
    
    //是否在微信打开
    function isWeiXin(){
        var ua = navigator.userAgent.toLowerCase();
        if(ua.indexOf('micromessenger') != -1) {
            return true;
        } else {
            return false;
        }
    }
  • 相关阅读:
    渐变的圆
    画一组同心圆
    画五角星
    照猫画虎求阶乘
    字符串逆序输出
    格式化输出
    计算矩形面积
    字符串反码A
    快乐数字
    Maratona Brasileira de Popcorn( 二分答案+暴力 )
  • 原文地址:https://www.cnblogs.com/guiyishanren/p/12205148.html
Copyright © 2011-2022 走看看