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 }

猜你喜欢

转载自www.cnblogs.com/xinwenpeng/p/9818749.html