Detect Metro UI Version of IE

后端 未结 11 1791
轻奢々
轻奢々 2020-12-02 21:22

What\'s the fastest method, to detect User-Agent as metro UI version of internet-explorer >=10 ?

11条回答
  •  星月不相逢
    2020-12-02 21:37

    Thanks John Rajakumar and Alexis Pigeon. I was able to use your Metro IE check as the basis to load a separate CSS style sheet for Metro tablets (MS Surface). To add a bit more certainty in my mind, I used cssuseragent to detect IE10 first, and then combined both tests in a final yepnope test.

    var IEmetrotest = ((cssua.userAgent.ie > 9) && (metrotest()));
    yepnope({
        test: IEmetrotest,
        yep : ['ie_metro.css']
        });
    

    Tested it in Browserstack and it's working as expected. (I would have up-ticked you, but don't have enough points yet.)

    // Minor revisions to isBrowserSupportPlugin() previously posted
    // Renamed function to metrotest() and inverted the returned value. 
    var errorName = null;
    function metrotest() {
        var supported = null; 
        try {
            new ActiveXObject("");
        }
        catch (e) {
            // FF has ReferenceError here
            errorName = e.name; 
        }     
        try {
            supported = !!new ActiveXObject("htmlfile");
        } catch (e) {
            supported = false;
        }
        if(errorName != 'ReferenceError' && supported==false){
            supported = false;
        }else{
            supported =true;
        }
        return !supported;
    }
    

提交回复
热议问题