美文网首页html5
js常用判断设备方法

js常用判断设备方法

作者: 前端小旋风 | 来源:发表于2019-07-15 10:46 被阅读0次

    以下就是整理的一些方法

    // 运行环境是浏览器
    
    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

    相关文章

      网友评论

        本文标题:js常用判断设备方法

        本文链接:https://www.haomeiwen.com/subject/rdbgkctx.html