Jquery检查浏览器是否为IE [英] Jquery check if browser is IE

查看:133
本文介绍了Jquery检查浏览器是否为IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How would i check if the users browser is IE? i have this code here but it is not working.

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


推荐答案

http://ajaxian.com/archives/attack-of-the-ie-conditional-comment\"> James Padolsey的此解决方案:

Try this solution by James Padolsey:

// ----------------------------------------------------------
// 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;
}());

注释中还有其他有趣的解决方案。

There are other interesting solutions in the comments as well.

这篇关于Jquery检查浏览器是否为IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆