判断当前浏览器类型

是否是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;
    }

获取当前浏览器的内核类型

function GetMobelType() {
    var browser = {
        versions: function () {
            var u = window.navigator.userAgent;
            var ua = navigator.userAgent.toLowerCase();
            console.log(u); //Safari浏览器 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15
            return {
                trident: u.indexOf('Trident') > -1, //IE内核
                presto: u.indexOf('Presto') > -1, //opera内核
                Alipay: u.indexOf('Alipay') > -1, //支付宝
                webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
                iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
                //iPhone: u.match(/iphone|ipod|ipad/),//
                iPad: u.indexOf('iPad') > -1, //是否为iPad
                webApp: u.indexOf('Safari') == -1, //是否为web应用程序,没有头部与底部
                // weixin:  u.indexOf('MicroMessenger')  >  -1, //是否为微信浏览器
                weixin: ua.match(/MicroMessenger/i) && ua.match(/MicroMessenger/i).includes("micromessenger"),
                // qq: u.match(/\sQQ/i) !== null, //是否QQ
                qq: ua.match(/QQ/i) && ua.match(/QQ/i).includes("qq"),
                Safari: u.indexOf('Safari') > -1,
                ///Safari浏览器,
            };
        }()
    };
    return browser.versions;
}

    if (GetMobelType().mobile) {
        console.log('mobile');
        //移动端
        if (GetMobelType().android) {
            if (GetMobelType().weixin || GetMobelType().qq) {
            } else {
            }
        }
        if (GetMobelType().ios || GetMobelType().iPhone || GetMobelType().iPad) {
            if (GetMobelType().weixin || GetMobelType().qq) { // ios的苹果浏览器
            } else {
                // alert('mobile ios/iphone/ipad  not qq');
            };
        }

    } else {
        //pc端
        console.log('pc');
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值