javascript - 如何检测Internet Explorer 11及以下版本?

标签 javascript internet-explorer

我想知道如何检测浏览我网站的用户是否使用 Internet Explorer 11 或更低版本的 Javascript。

它应该兼容并适用于所有这些版本。

如何实现?

最佳答案

给你,这应该适合你:

//Per Icycool, one liner
//function isIE(){
//                 return window.navigator.userAgent.match(/(MSIE|Trident)/);
//               }

function isIE() {
    const ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
    const msie = ua.indexOf('MSIE '); // IE 10 or older
    const trident = ua.indexOf('Trident/'); //IE 11
    
    return (msie > 0 || trident > 0);
}


//function to show alert if it's IE
function ShowIEAlert(){
    if(isIE()){
       alert("User is using IE");
    }
}

关于javascript - 如何检测Internet Explorer 11及以下版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49986720/

相关文章:

javascript - IE内存消耗分析工具

javascript - jQuery 添加类到未删除的单选框

javascript - dojo 复选框已选中但直到鼠标悬停才显示

Javascript,代码如何在语法上有效并且无法运行?

jquery - Internet Explorer (IE) 的 CSS/HTML 兼容性问题

css - IE 评论根本不在页面上呈现 css

javascript - 如何在字符串之间的对象上调用函数?

javascript - 使用 Val() 获取与所选单选按钮相同的值

javascript - “checked”为 null 或不是对象 - 仅限 IE

wordpress - 在 Internet Explorer 中按跳过链接后 JAWS 不读取 div