zoukankan      html  css  js  c++  java
  • javascript判断浏览器是否为IE内核,edge

      当前IE内核和edge浏览器还有很多功能不支持,例如Promise,Webgl2.0,所以经常需要判断当前浏览器的种类,可以使用如下方法判断是否为IE内核或者edge。

     1 var getExplorer = (function () {
     2     var explorer = window.navigator.userAgent,
     3         compare = function (s) { return (explorer.indexOf(s) >= 0); },
     4         ie11 = (function () { return ("ActiveXObject" in window) })();
     5     if (compare("MSIE") || ie11) { return 'ie'; }
     6     else if (compare("Firefox") && !ie11) { return 'Firefox'; }
     7     else if (compare("Chrome") && !ie11) {
     8         if (explorer.indexOf("Edge") > -1) {
     9             return 'Edge';
    10         } else {
    11             return 'Chrome';
    12         }
    13     }
    14     else if (compare("Opera") && !ie11) { return 'Opera'; }
    15     else if (compare("Safari") && !ie11) { return 'Safari'; }
    16 
    17 })()
    18 
    19 if (getExplorer == 'ie') {
    20     alert('当前浏览器内核为IE内核,请使用非IE内核浏览器!');
    21 }
    22 if (getExplorer == 'Edge') {
    23     alert('当前浏览器为Edge,请使用非IE内核浏览器!');
    24 }
    //qq911322692 欢迎添加 一起讨论编程学习经验
  • 相关阅读:
    好的Qt学习资料
    QT QMap介绍与使用
    Qt缺少调试器
    vs2012+Qt5.3.1环境添加新的ui界面的方法
    QT定时器的使用
    Qt中forward declaration of struct Ui::xxx的解决
    linux-svn命令
    如何编写Windows服务
    为你的爬虫提提速?
    Python爬虫的N种姿势
  • 原文地址:https://www.cnblogs.com/xinwenpeng/p/9818749.html
Copyright © 2011-2022 走看看