javascript - jquery判断浏览器是否为IE

标签 javascript jquery html css internet-explorer

如何检查用户浏览器是否为 IE?我这里有这段代码,但它不起作用。

if($.browser.msie && $.browser.version <= 9)
{
    alert('You Are Using An Outdated Browser! Switch To Chrome Or FireFox.');   
}

最佳答案

尝试 this solution詹姆斯·帕多尔西:

// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
//     ie === undefined
// If you're in IE (>5) then you can determine which version:
//     ie === 7; // IE7
// Thus, to detect IE:
//     if (ie) {}
// And to detect the version:
//     ie === 6 // IE6
//     ie> 7 // IE8, IE9 ...
//     ie <9 // Anything less than IE9
// ----------------------------------------------------------
var ie = (function(){
    var undef, v = 3, div = document.createElement('div');

    while (
        div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
        div.getElementsByTagName('i')[0]
    );

    return v> 4 ? v : undef;
}());

评论中还有其他有趣的解决方案。

关于javascript - jquery判断浏览器是否为IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15056620/

相关文章:

javascript - 响应 jQuery post 请求而设置的变量

javascript - 单击提交后,包含注册表单的 Div 消失。

javascript - Jquery忽略具有 "disabled"类的元素

javascript - 只允许数字的实时输入文本过滤

jquery - RoR - 如何在下拉列表中添加图标

html - 通知未显示在特定按钮上

javascript - 在加载时为选择框设置值时出现问题

javascript - Angularjs对页面加载调用函数

javascript - 如何使用 html2Canvas 自动下载截图

javascript - 避免嵌套条件中的重复