How to detect IE7 and IE8 using jQuery.support

前端 未结 12 1246
忘掉有多难
忘掉有多难 2020-12-08 10:46

How can I detect IE 7 and IE 8 using jQuery.support properties?

Is it possible to detect the browser versions using jQuery.support or just those blah blah blah brows

12条回答
  •  旧巷少年郎
    2020-12-08 10:59

    I added few lines of Javascript to make it work again:

    jQuery.uaMatch = function (ua) {
        ua = ua.toLowerCase();
    
        var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
                /(webkit)[ \/]([\w.]+)/.exec(ua) ||
                /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
                /(msie) ([\w.]+)/.exec(ua) ||
                ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
                [];
    
        return {
            browser: match[ 1 ] || "",
            version: match[ 2 ] || "0"
        };
    };
    
    if (!jQuery.browser) {
        matched = jQuery.uaMatch(navigator.userAgent);
        browser = {};
    
        if (matched.browser) {
            browser[ matched.browser ] = true;
            browser.version = matched.version;
        }
    
        // Chrome is Webkit, but Webkit is also Safari.
        if (browser.chrome) {
            browser.webkit = true;
        } else if (browser.webkit) {
            browser.safari = true;
        }
    
        jQuery.browser = browser;
    }
    

提交回复
热议问题