如何检查用户浏览器是否为 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/