判断浏览器类型--移动端(非完整版)

    var client = {
        UA: function () {
            var browser = {
                versions: (function () {
                    var u = navigator.userAgent
                    var iosSlice = u.substring(
                        u.indexOf('singchina-ios-version-') +
                        'singchina-ios-version-'.length
                    )
                    var androidSlice = u.substring(
                        u.indexOf('singchina-Android-version-') +
                        'singchina-Android-version-'.length
                    )
                    return {
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
                        weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
                        mini: u.indexOf('miniProgram') > -1, //是否微信 (2015-01-22新增)
                        uc: u.indexOf('UCBrowser') > -1,
                        safari: u.indexOf('Safari') > -1,
                        AgentWeb: u.indexOf('AgentWeb') > -1,
                        scAndroid: u.indexOf('singchina-Android') > -1,
                        sciOS: u.indexOf('singchina-ios') > -1,
                        mobileWeibo: u.match(/WeiBo/i) == 'weibo',
                        iosVersion: u.indexOf('singchina-ios-version-') > -1 ?
                            iosSlice.slice(0, iosSlice.indexOf('-')) : '0000',
                        androidVersion: u.indexOf('singchina-Android-version-') > -1 ?
                            androidSlice.slice(0, androidSlice.indexOf('-')) : '0000',
                    }
                })(),
            }
            // client.versions.iosVersion = browser.versions.iosVersion
            // client.versions.androidVersion = browser.versions.androidVersion

            if (browser.versions.mini) {
                return 'wx'
            } else if (browser.versions.weixin) {
                return 'wxh5'
            } else if (browser.versions.mobileWeibo) {
                return 'mobileWeibo'
            } else if (browser.versions.scAndroid) {
                return 'android'
            } else if (browser.versions.sciOS) {
                return 'ios'
            } else {
                return 'h5'
            }
        },
}
posted @ 2020-11-18 17:38  heart中的烦恼哟  阅读(125)  评论(0编辑  收藏  举报