hacklab 发表于 2016-1-2 15:33:50

JS 曲分浏览器 temp

Safari
Safari典型的userAgent如下:
Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13
Mozilla/5.0 (iPhone; U; CPU like Mac OS X) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3
其版本号是Version之后的数字。
Chrome
目前,Chrome的userAgent是:
Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13
其中,版本号在Chrome之后的数字。
<script type="text/javascript">
      var Sys = {};
      var ua = navigator.userAgent.toLowerCase();
      var s;
      (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s :
      (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s :
      (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s :
      (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s :
      (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s : 0;
      //以下进行测试
      if (Sys.ie) document.write('IE: ' + Sys.ie);
      if (Sys.firefox) document.write('Firefox: ' + Sys.firefox);
      if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
      if (Sys.opera) document.write('Opera: ' + Sys.opera);
      if (Sys.safari) document.write('Safari: ' + Sys.safari);
    </script>
页: [1]
查看完整版本: JS 曲分浏览器 temp