各个端类型判断

const ua = navigator.userAgent;
this.ua = ua;
this.trident = ua.indexOf('Trident') > -1; // ie
this.presto = ua.indexOf('Presto') > -1; // opera
this.webKit = ua.indexOf('AppleWebKit') > -1; // applewebkit
this.gecko = ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') == -1; // firefox
this.mobile = !!ua.match(/AppleWebKit.*Mobile.*/); // mobile
this.ios = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios
this.android = ua.indexOf('Android') > -1 || ua.indexOf('Linux') > -1; // android or uc
this.iphone = ua.indexOf('iPhone') > -1; // iphone or qq
this.ipad = ua.indexOf('iPad') > -1; // ipad
this.weibo = /weibo/i.test(ua) ? true : false;
this.weixin = /micromessenger/i.test(ua) ? true : false;
this.app = /jumei/i.test(navigator.userAgent) ? true : false;
this.wkWebview = /WKWebView\/1/g.test(ua) ? true : false;
this.isHybrid = (window as any)._isHybrid

posted @ 2018-05-18 17:18  南韵  阅读(176)  评论(0编辑  收藏  举报