美文网首页
利用js识别用户当前浏览器具体类型(非内核)和电脑系统类型

利用js识别用户当前浏览器具体类型(非内核)和电脑系统类型

作者: 深漂浪子 | 来源:发表于2019-06-04 18:00 被阅读0次

    废话不多说,直接给你们上代码吧:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
        </head>
        <body>
            <script>
    
                //识别浏览器类型 火狐、谷歌、百度、360、QQ等
                function checkBrowser(){
                    var ua = navigator.userAgent.toLocaleLowerCase();
                    var browserType=null;
                    if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
                       browserType = "IE";
                       browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];
                    } else if (ua.match(/firefox/) != null) {
                       browserType = "火狐";
                    }else if (ua.match(/ubrowser/) != null) {
                       browserType = "UC";
                    }else if (ua.match(/opera/) != null) {
                       browserType = "欧朋";
                    } else if (ua.match(/bidubrowser/) != null) {
                       browserType = "百度";  
                    }else if (ua.match(/metasr/) != null) {
                       browserType = "搜狗";  
                    }else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
                       browserType = "QQ";
                    }else if (ua.match(/maxthon/) != null) {
                       browserType = "遨游";
                    }else if (ua.match(/chrome/) != null) {
                        var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");
                        function _mime(option, value) {
                            var mimeTypes = navigator.mimeTypes;
                            for (var mt in mimeTypes) {
                            if (mimeTypes[mt][option] == value) {
                                   return true;
                              }
                            }
                            return false;
                        }
                        if(is360){               
                            browserType = '360';  
                        }else{  
                            browserType = "谷歌";  
                        }  
    
                    }else if (ua.match(/safari/) != null) {
                       browserType = "Safari";
                    }
                    return browserType;
                }
    
                //识别用户目前所使用的系统类别
                function detectOS() {
                    var sUserAgent = navigator.userAgent;
                    var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
                    var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
                    if (isMac) return "Mac";
                    var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
                    if (isUnix) return "Unix";
                    var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
                    if (isLinux) return "Linux";
                    if (isWin) {
                        var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
                        if (isWin2K) return "Win2000";
                        var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
                        if (isWinXP) return "WinXP";
                        var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
                        if (isWin2003) return "Win2003";
                        var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
                        if (isWinVista) return "WinVista";
                        var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
                        if (isWin7) return "Win7";
                    }
                    return "other";
                }
    
                document.writeln("你的浏览器类型是:" + checkBrowser());            
                 document.writeln("<br/>" );
                document.writeln("你的操作系统类型是:" + detectOS());
    
            </script>
        </body>
    </html>
    
    

    相关文章

      网友评论

          本文标题:利用js识别用户当前浏览器具体类型(非内核)和电脑系统类型

          本文链接:https://www.haomeiwen.com/subject/pugcxctx.html