//  1.9以后取消了msie这些私有方法判断。这里封装加回。
var matched = (function(ua) {
    ua = ua.toLowerCase();

    var match = /(opr)[\/]([\w.]+)/.exec(ua) ||
        /(chrome)[ \/]([\w.]+)/.exec(ua) ||
        /(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
        /(webkit)[ \/]([\w.]+)/.exec(ua) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
        /(msie) ([\w.]+)/.exec(ua) ||
        ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec(ua) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];

    var platform_match = /(ipad)/.exec(ua) ||
        /(iphone)/.exec(ua) ||
        /(android)/.exec(ua) ||
        /(windows phone)/.exec(ua) ||
        /(win)/.exec(ua) ||
        /(mac)/.exec(ua) ||
        /(linux)/.exec(ua) ||
        /(cros)/i.exec(ua) || [];

    return {
        browser: match[3] || match[1] || "",
        version: match[2] || "0",
        platform: platform_match[0] || ""
    };
})(window.navigator.userAgent);
var browser = {};
if (matched.browser) {
    browser[matched.browser] = true;
    browser.version = matched.version;
    browser.versionNumber = parseInt(matched.version, 10);
}

if (matched.platform) {
    browser[matched.platform] = true
}


if (browser.chrome || browser.opr || browser.safari) {
    browser.webkit = true;
}

if (browser.rv) {
    var ie = 'msie';
    matched.browser = ie;
    browser[ie] = true;
}

if (browser.opr) {
    var opera = 'opera';
    matched.browser = opera;
    browser[opera] = true;
}

if (browser.safari && browser.android) {
    var android = "android";
    matched.browser = android;
    browser[android] = true;
}
browser.name = matched.browser;
browser.platform = matched.platform;
app.browser = browser;
$.browser = app.browser;

相关文章:

  • 2021-12-03
  • 2021-05-31
  • 2021-08-14
  • 2022-12-23
  • 2021-12-09
  • 2021-08-27
猜你喜欢
  • 2021-05-01
  • 2021-07-30
  • 2021-07-25
  • 2021-12-16
  • 2021-09-02
  • 2022-12-23
相关资源
相似解决方案