0 1215

//判断浏览器内核、手机系统等,使用 browser.version.mobile


var browser = {

  version: function () {

    var u = navigator.userAgent;

    var ua = navigator.userAgent.toLocaleLowerCase();

    var app = navigator.appVersion;

    return {

      trident: u.indexOf('Trident') > -1, // IE内核

      presto: u.indexOf('Presto') > -1, // opera内核

      webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核

      gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, // 火狐内核

      mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), // 是否为移动终端

      ios: !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), // IOS终端

      android: u.indexOf('Android') > -1 || u.indexOf('Mac') > -1, // 安卓终端

      iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, // 是否为iphone或QQHD浏览器

      iPad: u.indexOf('iPad') > -1, // 是否为iPad

      Safari: u.indexOf('Safari') > -1, // Safari浏览器

      QQbrw: u.indexOf('MQQBrowser') > -1, // QQ浏览器

      weiXin: u.indexOf('MicroMessenger') > -1, // 微信

      QQ: ua.match(/QQ/i) == "qq", // QQ

      weiBo: ua.match(/WeiBo/i) == "weibo", // 微博

      ucLowEnd: u.indexOf('UCWEB7.') > -1, //

      ucSpecial: u.indexOf('rv:1.2.3.4') > -1,

      webview: !(u.match(/Chrome/([d.]+)/) || u.match(/CriOS/([d.]+)/)) && u.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/),

      ucweb: function () {

        try {

          return parseFloat(u.match(/ucwebd+.d+/gi).toString().match(/d+.d+/).toString()) >= 8.2

        } catch (e) {

          if (u.indexOf('UC') > -1) {

            return true;

          }

          return false;

        }

      }(),

      Symbian: u.indexOf('Symbian') > -1,

      ucSB: u.indexOf('Firofox/1.') > -1

    };

  }()

};



[分类]
[来源] http://erlangyun.com/p/id/68.html
[声明] 本站资源来自用户分享,如损害你的权益请联系客服QQ:120074275给予处理。