获取当前是何设备,来区分不同的事件及渲染模式
navigator.userAgent
封装好函数直接调用,利用switch直接进行判断即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| export function currDevice() { const u = navigator.userAgent; const app = navigator.appVersion; const browserLang = (navigator.browserLanguage || navigator.language).toLowerCase(); const deviceBrowser = (() => { return { trident: u.indexOf('Trident') > -1, presto: u.indexOf('Presto') > -1, webKit: u.indexOf('AppleWebKit') > -1, gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') === -1, mobile: !!u.match(/AppleWebKit.*Mobile.*/), ios: !!u.match(/\(i[^;]+;( U;)? CPU.Mac OS X/), android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, iPhone: u.indexOf('iPhone') > -1, iPad: u.indexOf('iPad') > -1, webApp: u.indexOf('Safari') === -1, weixin: u.indexOf('MicroMessenger') > -1, qq: u.match(/\sQQ/i) === "qq", }; })(); return deviceBrowser; }
|
祝君无Bug~