页面环境判断

项目中我们经常会使用一套H5页面内嵌到APP,小程序中。有些场景就需要根据不同的环境,来处理一些需求,这时候就需要进行环境判断了。

const ua = window.navigator.userAgent.toLowerCase();
const AppUtils = {
    isApp: ua.indexOf('lvmm') > -1,
    isIOS: ua.indexOf('iphone') > -1 || ua.indexOf('ipad') > -1, //ios
    isIphoneX: ua.indexOf('iphone') > -1 && (
        (screen.width === 375 && screen.height === 812) || (screen.width === 414 && screen.height === 896)
    ), //IOS-IphoneX
    isAndriod: ua.indexOf('lvmm') > -1 && ua.indexOf('android') > -1,
    isWX:ua.match(/MicroMessenger/i) == 'micromessenger',//微信环境
    isWXSP: window.__wxjs_environment === 'miniprogram' || ua.indexOf('miniprogram') > -1, //微信小程序环境
    IsBD: ua.indexOf('baidu') > -1
}

 

posted @ 2020-08-18 14:18  #小小佳  阅读(412)  评论(0编辑  收藏  举报