js常用判断设备方法

以下就是整理的一些方法

// 运行环境是浏览器

export const inBrowser = typeof window !== 'undefined';

// 运行环境是微信

export const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform;

export const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase();

// 浏览器 UA 判断

export const UA = inBrowser && window.navigator.userAgent.toLowerCase();

export const isIE = UA && /msie|trident/.test(UA);

export const isIE9 = UA && UA.indexOf('msie 9.0') > 0;

export const isEdge = UA && UA.indexOf('edge/') > 0;

export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android');

export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios');

export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;

我建了一个前端微信交流群,欢迎大家加入,qq中转群号:1076484243

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容