美文网首页
APP H5分享,判断设备的操作

APP H5分享,判断设备的操作

作者: 俗人彭jin | 来源:发表于2020-03-26 16:16 被阅读0次
/**
     * 获取设备终端
     * @returns {string}
     */
    function getOs() {
        var os = ''
        var ua = window.navigator.userAgent.toLowerCase(),
            app = window.navigator.appVersion;
        if (!!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
            // ios端
            os = 'ios'
        }
        else if (ua.indexOf('android') > -1 || ua.indexOf('Adr') > -1) {
            // android端
            os = 'android'
        }
        if (ua.match(/WeiBo/i) == "weibo") { // 微博
            os = 'wb'
        }
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            // 微信浏览器
            os = 'wx'
        }
        if (ua.match(/QQ/i) == "qq") {
            //在QQ空间打开
            os = 'qq'
        }
        alert(os)
        return os
    }

相关文章

网友评论

      本文标题:APP H5分享,判断设备的操作

      本文链接:https://www.haomeiwen.com/subject/ctmcuhtx.html