js判断当前的浏览器环境是,微信环境,IE环境还是谷歌火狐浏览器

const {userAgent:UA} = navigator;
const UA_L = UA.toLowerCase();
export  const Device = {
   trident: UA.includes('Trident'),         //IE内核
   presto: UA.includes('Presto'),           //opera内核
   iPad: UA.includes('iPad'),               //是否iPad
   iPhone: UA.includes('iPhone'),           //是否为iPhone或者QQHD浏览器
   webKit: UA.includes('AppleWebKit'),      //苹果、谷歌内核
   webApp: UA.indexOf('Safari') === -1,     //是否web应该程序,没有头部与底部
   mobile: !!UA.match(/AppleWebKit.*Mobile.*/),                        //是否为移动终端
   ios: !!UA.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),                   //ios终端
   android: UA.includes('Android') || UA.includes('Linux'),     //android终端或uc浏览器
   gecko: UA.includes('Gecko') && UA.indexOf('KHTML') === -1,   //火狐内核
   wechat: UA_L.toLowerCase().match(/MicroMessenger/i) == 'micromessenger',     // 微信
   is: key=>Device[key]
};

使用方法 例如:判断是不是微信支付

Device.wechat

猜你喜欢

转载自blog.csdn.net/u010505805/article/details/93064784