美文网首页
js实例——浏览器类型匹配

js实例——浏览器类型匹配

作者: blank的小粉er | 来源:发表于2017-07-20 10:37 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <h1>浏览器的类型</h1>
        <hr>
        <script>
            document.write("userAgent : "+navigator.userAgent+'<br>');
    
    
            function uaMatch( ua ){
                var match = /(chrome)\/([\w.]+)/i.exec(ua) || 
                            /(Firefox)\/([\w.]+)/i.exec(ua) ||
                            /(MSIE) ([\w.]+)/i.exec(ua) ||
                            ua.indexOf('Trident') >= 0 && /(rv):([\w.]+)/i.exec(ua) ||
                            /(Webkit)[ \/]([\w.]+)/i.exec(ua) ||
                            /(Gecko)[ \/]([\w.]+)/i.exec(ua);
    
                //console.log(match);
                return {
                    "browser":match[1],
                    "version":match[2]
                };
            }
    
            var v = uaMatch(navigator.userAgent);
    
    
            document.write('浏览器名 : '+v.browser+'<br>');
            document.write('浏览器版本 : '+v.version+'<br>');
        </script>
    
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:js实例——浏览器类型匹配

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