js判断当前是什么设备

js判断当前是什么设备

/**
         * 判断当前是什么设备
         * @returns {string}
         */
        getIsApps: function() {
            var u = navigator.userAgent;
            var ua = navigator.userAgent.toLowerCase();
            var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
            var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
            var isHsApp = (u.indexOf("_hsApp_") != -1) || (u.indexOf("entApp") != -1);
            var isHsEntApp = u.indexOf("entApp") != -1;
            var isWeixin = ua.indexOf('micromessenger') != -1;
            var isAliPay = ua.indexOf('alipayclient') != -1;
            var isWeb = !isHsApp && !isWeixin && !isAliPay;
            var obj = {
                isHsApp: isHsApp, //互生App终端
                isHsEntApp: isHsEntApp, //互生企业App终端
                isAndroid: isAndroid, //android终端
                isiOS: isiOS, //ios终端
                isWeixin: isWeixin, //微信终端
                isAliPay: isAliPay, //支付宝终端
                isWeb: isWeb, //浏览器终端
            }
            return obj;
        },

 

posted @ 2022-04-25 11:31  时光独醒  阅读(12)  评论(0编辑  收藏  举报