zoukankan      html  css  js  c++  java
  • js获取浏览器版本信息

    //获取当前浏览器类型和版本号
    "use strict";
    let agent = navigator.userAgent.toLowerCase();
    let regStr_ff = /firefox/[d.]+/gi;
    let regStr_chrome = /chrome/[d.]+/gi;
    
    //IE11以下
    if (agent.indexOf("msie") > 0) {
        pass;
    }
    
    //IE11版本中不包括MSIE字段
    if (agent.indexOf("trident") > 0 && agent.indexOf("rv") > 0) {
        pass;
    }
    
    //firefox
    if (agent.indexOf("firefox") > 0) {
        let num = agent.match(regStr_ff)[0].match(/[d.]+/)[0].substr(0, 2);
        if (num < 58) {
           pass;
        }
    }
    
    //Chrome
    if (agent.indexOf("chrome") > 0) {
        let num = agent.match(regStr_chrome)[0].match(/[d.]+/)[0].substr(0, 2);
        if (num < 61) {
            pass;
        }
    }

    在HTML <head> 标签中引入js 即可

  • 相关阅读:
    LibreOJ2095
    Codeforces
    LibreOJ2241
    LibreOJ2044
    LibreOJ2043
    LibreOJ2045
    LibreOJ2042
    LibreOJ2097
    洛谷P4175
    POJ2888
  • 原文地址:https://www.cnblogs.com/eunuch/p/10190513.html
Copyright © 2011-2022 走看看