zoukankan      html  css  js  c++  java
  • 实用的js判断浏览器类型及版本

    代码:

     1 <html xmlns="http://www.w3.org/1999/xhtml" >
    2 <head>
    3 <title>实用的js判断浏览器类型及版本</title>
    4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    5 <script language="JavaScript">
    6 var imyeah={};
    7 var ua=navigator.userAgent.toLowerCase();
    8 var s;
    9 (s=ua.match(/msie ([\d.]+)/)) ? imyeah.ie=s[1] :
    10 (s=ua.match(/firefox\/([\d.]+)/)) ? imyeah.firefox=s[1] :
    11 (s=ua.match(/chrome\/([\d.]+)/)) ? imyeah.chrome=s[1] :
    12 (s=ua.match(/opera.([\d.]+)/)) ? imyeah.opera=s[1] :
    13 (s=ua.match(/version\/([\d.]+).*safari/)) ? imyeah.safari=s[1] : 0;
    14
    15 //以下进行测试
    16 if(imyeah.ie) document.write('IE: '+imyeah.ie);
    17 if(imyeah.firefox) document.write('Firefox: '+imyeah.firefox);
    18 if(imyeah.chrome) document.write('Chrome: '+imyeah.chrome);
    19 if(imyeah.opera) document.write('Opera: '+imyeah.opera);
    20 if(imyeah.safari) document.write('Safari: '+imyeah.safari);
    21 </script>
    22 </head>
    23 <body>
    24 </body>
    25 </html>

    这段代码非常简短,但能够准确判断ie、FF、Chrome、Opera、Safari浏览器及其版本,非常实用。

  • 相关阅读:
    5、流程控制
    4、字典和元祖
    3、列表操作
    2、字符串和数据类型
    1.标识符练习
    使用xpath提取页面所有a标签的href属性值
    网页提取所有邮箱
    正则表达式
    提取包含QQ的文本为QQ邮箱
    python继承小demo
  • 原文地址:https://www.cnblogs.com/imyeah/p/2298793.html
Copyright © 2011-2022 走看看