JS获取当前使用的浏览器名字以及版本号

来源:互联网 发布:淘宝图片放大镜功能 编辑:程序博客网 时间:2024/05/23 07:25
<!DOCTYPE html><html>  <head>    <title>JS获取当前使用的浏览器名字以及版本号</title>    <meta charset="utf-8">    <meta name="keywords" content="keyword1,keyword2,keyword3">    <meta name="description" content="this is my page">    <meta name="content-type" content="text/html; charset=UTF-8">    <script type="text/javascript">var userAgent=window.navigator.userAgent,      rMsie=/(msie\s|trident.*rv:)([\w.]+)/,  rFirefox=/(firefox)\/([\w.]+)/,  rOpera=/(opera).+version\/([\w.]+)/,  rChrome=/(chrome)\/([\w.]+)/,  rSafari=/version\/([\w.]+).*(safari)/;function uaMatch(ua){var match=rMsie.exec(ua); if(match != null){ return {browser:"IE",version:match[2] || "0"}; } var match=rFirefox.exec(ua); if(match != null) { return {browser:match[1] || "",version:match[2] || "0"};   } var match=rOpera.exec(ua);   if(match != null) {     return {browser:match[1] || "",version:match[2] || "0"};   }   var match=rChrome.exec(ua); if(match != null) {     return {browser:match[1] || "",version:match[2] || "0"};   }   var match=rSafari.exec(ua); if(match != null) { return {browser:match[2] || "",version:match[1] || "0"};   }   if(match != null) {     return {browser:"",version:"0"};   } }function init(){var browser=""; var version="";var browserMatch=uaMatch(userAgent.toLowerCase()); if(browserMatch.browser){ browser=browserMatch.browser; version=browserMatch.version; }alert(browser+"  "+version);}    </script>  </head>  <body onload="init()">      </body></html>

0 0
原创粉丝点击