zoukankan      html  css  js  c++  java
  • js 判断浏览器型号


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    </head>
    <body>
    <script>
    detectBrowser();
    function detectBrowser() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE浏览器
    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
    var isChrome = userAgent.indexOf("Chrome") > -1;
    var isEdge = userAgent.indexOf("Windows NT 6.1;") > -1 && userAgent.indexOf("Trident/7.0;") > -1;
    var browserName = "";

    if (isIE) {
    //var IE5 = IE55 = IE6 = IE7 = IE8 = false;
    var reIE = new RegExp("MSIE (\d+\.\d+);");
    reIE.test(userAgent);
    var fIEVersion = parseFloat(RegExp["$1"]);
    browserName = "IE浏览器" + fIEVersion;
    } else if (isFF) {
    browserName = "火狐浏览器";
    } else if (isChrome) {
    browserName = "谷歌浏览器";
    } else if (isEdge) {
    browserName = "Edge浏览器";
    }
    output(browserName);
    }

    function output(browserName) {
    document.write(browserName + "<br/>");
    document.write("new Date():" + new Date());
    }

    </script>
    <body>
    </html>

  • 相关阅读:
    正则表达式学习网站
    Longest Substring Without Repeating Characters
    保留小数点后几位数字
    ReentrantLock和synchronized的区别随笔
    范型 小编
    两个线程交替打印字符串
    Gray Code
    Ajax
    堆排序
    Clone Graph
  • 原文地址:https://www.cnblogs.com/cxcoder/p/9542131.html
Copyright © 2011-2022 走看看