检测浏览器及版本

var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
!!window.ActiveXObject || "ActiveXObject" in window
        ? (Sys.ie = (ua.match(/rv:([\d.]+)/) || ua.match(/msie ([\d.]+)/))[1])
        : (s = ua.match(/edg\/([\d.]+)/))
        ? (Sys.edge.version = s[1])
        : (s = ua.match(/firefox\/([\d.]+)/))
        ? (Sys.firefox.version = s[1])
        : (s = ua.match(/(?:opera|opr).([\d\.]+)/))
        ? (Sys.opera.version = s[1])
        : (s = ua.match(/chrome\/([\d.]+)/))
        ? (Sys.chrome.version = s[1])
        : (s = ua.match(/version\/([\d.]+).*safari/))
        ? (Sys.safari.version = s[1])
        : 0;
//以下进行测试
if (Sys.ie) document.write("IE: " + Sys.ie);
if (Sys.edg) document.write("Edge: " + Sys.edg);
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);

// 判断浏览器是否支持esmodule
function supportsDynamicImport() {
    try {
      new Function('import("")');
      return true;
    } catch (err) {
      return false;
    }
}

你可能感兴趣的:(检测浏览器及版本)