How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

前端 未结 25 3215
谎友^
谎友^ 2020-11-22 06:19

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

I tried this, but

25条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 06:42

    use babel or typescript for convert this code js

    const browser = () => {
        // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3576.0 Safari/537.36"
        // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.17 Safari/537.36"
        // "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"
        // "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0"
        // "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko"
        // "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"
        // "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"
        // "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"
        // "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"
        const _userAgent = navigator.userAgent;
        const br = {
            "Chrome": "Chrome",
            "Edge": "Edge",
            "Firefox": "Firefox",
            ".NET CLR": "Internet Explorer 11",
        };
        const nobr = {
            "MSIE 10.0": "Internet Explorer 10",
            "MSIE 9.0": "Internet Explorer 9",
            "MSIE 8.0": "Internet Explorer 8",
            "MSIE 7.0": "Internet Explorer 7"
        };
        let thisBrow = "Unknown";
        for (const keys in br) {
            if (br.hasOwnProperty(keys)) {
                if (_userAgent.includes(keys)) {
    
                    thisBrow = br[keys];
    
                    for (const key in nobr) {
                        if (_userAgent.includes(key)) {
                            thisBrow = nobr[key];
                        }
                    }
    
                }
            }
        }
    
        return thisBrow;
    };

提交回复
热议问题