判断h5页面打开环境

在开发中,经常会碰到在不同平台进行不同操作,比如常见的微信,QQ……

function isEquipment(){
    let UA = navigator.userAgent,
        isAndroid = /android|adr|linux/gi.test(UA),
        isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
        isBlackBerry = /BlackBerry/i.test(UA),
        isWindowPhone = /IEMobile/i.test(UA),
        isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
    return{
        isAndroid: isAndroid,
        isIOS: isIOS,
        isMobile: isMobile,
        isWeixin: /MicroMessenger/gi.test(UA),
        isQQ: /QQ/gi.test(UA),
        isPC: !isMobile,
        isWeibo: /WeiBo/gi.test(UA)
    }
}
用法:
if(isEquipment().isWeixin || isEquipment().isQQ || isEquipment().isWeibo){    //是否是微信,QQ 微博环境            
                console.log('是否是微信');               
        }

小笔记来一波~~~
方便的话,别忘赞个撒^_^
     

你可能感兴趣的:(javascript)