首页 > 代码库 > JS判断浏览器

JS判断浏览器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">

         function getBrowserInfo(){
            var Info = {};
             var str = window.navigator.userAgent.toLowerCase();
             var bReg =/(msie|firefox|chrome|opera|version).*?([\d.]+)/;
             var infoArr = str.match(bReg);
             Info.browser = infoArr[1].replace(/version/, "safari");
             Info.ver = infoArr[2];
             return Info;
         }
         var BomInfo = getBrowserInfo();
         
         document.write(BomInfo.browser);
         document.write("</br>");
         document.write(BomInfo.ver);

    </script>
</body>
</html>

技术分享

JS判断浏览器