判断浏览器 终端

经过判断window是不是undefined,来判断运行环境是不是浏览器,在浏览器中,window不是undefined

  • var inBrowser = typeof window !== 'undefined';

判断代码是否运行在weex环境中,weex是阿里推出的一个库,能够用前端的js、html、css写移动端的项目

  • var inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform;

判断是weex下的移动端的哪一种环境

  • var weexPlatform = inWeex && WXEnvironment.platform.toLowerCase();

BOM中的navigation

  • var UA = inBrowser && window.navigator.userAgent.toLowerCase();

判断是否是ie

  • var isIE = UA && /msie|trident/.test(UA);

判断是否是ie9

  • var isIE9 = UA && UA.indexOf('msie 9.0') > 0;

判断是否是edge

  • var isEdge = UA && UA.indexOf('edge/') > 0;

判断是否是安卓

  • var isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android');

判断是否是 ios

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

判断是否是chrome

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

判断是否是 isPhantomJS。

  • var isPhantomJS = UA && /phantomjs/.test(UA);

判断是否是 火狐

  • var isFF = UA && UA.match(/firefox/(\d+)/);
-- 代码来自vue源码
相关文章
相关标签/搜索