js识别360浏览器

2,225 阅读1分钟
原文链接: blog.csdn.net

时隔2年才想起来,博客已经空窗好久….曾经信誓旦旦的想要每周一篇…. 也罢,废话不多说,之所以会去写这个js,当时纯粹是被逼的,然而写出来后,竟然还有点高兴… 整整花了我将近一周的时间,天天都是在查看控制台,感觉整个人都不好了… 以下是源码 :)

// 检测兼容模式下的360浏览器
    function checkIeFor360() {
        /**
         *
         * 截止20170731得到有差异的数据项
         *                                                      IE  搜狗  2345    遨游  QQ  360
         * _IE_DEVTOOLBAR_CONSOLE_COMMAND_LINE                   ×  √   √   √   √   √
         * window.maxConnectionsPerServer                       10(http协议下值为6)  10  10(http协议下值为6)  10  6   10(http协议下值为6)
         * navigator.userAgent                                  ×   √/×(IE9及以上) ×   ×   √   ×
         * window.external                                          [Sogou Explorer Object]
         * navigator.msDoNotTrack (IE10及以下)                 1   0   0   0   0   1
         * window.doNotTrack(IE11)                              1   null    null    null    null    1
         * navigator.msPointerEnabled                           TRUE    TRUE    FALSE   FALSE   TRUE    TRUE
         * window.screenLeft - window.screenX != 8 (IE9及以上) FALSE   TRUE    FALSE   FALSE   TRUE    TRUE
         * console.count(仅测试了IE7、8)                         undefined   undefined   undefined   undefined   undefined
         *
         */
        return ((navigator.msPointerEnabled == undefined ? true : navigator.msPointerEnabled)
        && (navigator.msDoNotTrack == 1 || window.doNotTrack == 1)
        && ((Number(window.screenX) ? (window.screenLeft - window.screenX != 8) : false)
        || ((navigator.userAgent.indexOf('MSIE 7.0') != -1 || navigator.userAgent.indexOf('MSIE 8.0') != -1) && console.count == undefined)));
    }

    // 检测极速内核下的360浏览器
    function checkChromeFor360() {
        var uas = navigator.userAgent.split(' '),
            result = false;
        // 排除ua自带标志的双核浏览器, 余下chrome,chromium及360浏览器
        if (uas[uas.length - 1].indexOf('Safari') == -1) {
            return result;
        }
        for (var key in navigator.plugins) {
            // np-mswmp.dll文件在chromium及chrome未查询到
            if (navigator.plugins[key].filename == 'np-mswmp.dll') {
                return !result;
            }
        }
        return result;
    }

    if (navigator.userAgent.indexOf('Safari') != -1) {
        document.writeln(checkChromeFor360());
    } else {
        document.writeln(checkIeFor360());
    }

哦,想起来,在GitHub上有预览的地址,欢迎访问测试