(不关心版本.IE或不是IE。)
答案 0 :(得分:10)
http://api.jquery.com/jQuery.browser/
isIE = $.browser.msie;
$.browser
同时被弃用,但尚未停用。应该使用$.support
代替。示例:$.support.boxModel
答案 1 :(得分:10)
我不会通过浏览器嗅探(即直接或通过Javascript框架)来实现,因为用户代理字符串很容易伪造(在这些情况下,取决于JavaScript,可以关闭)
在这种情况下(IE或不是),我会在您的HTML中使用conditional comments。无论JavaScript是否启用,它们都将始终有效。
答案 2 :(得分:1)
答案 3 :(得分:0)
<html>
<head>
</head>
<body>
<script type="text/javascript">
alert(navigator.appName);
</script>
</body>
</html>
回复'netscape'(适用于Firefox)或'Microsoft Internet Explorer'(当我尝试使用IE7时 - 未尝试其他平台)
例如,请参阅以下链接以获取更多信息。
http://www.javascriptkit.com/javatutors/navigator.shtml
这就是'if'/'else'结构的相同类型。
<html>
<head>
</head>
<body>
<script type="text/javascript">
if (navigator.appName=="Microsoft Internet Explorer") {
alert("This is IE!");
}
else {
alert("This is not IE!");
}
</script>
</body>
</html>
实际上你应该选择另一篇文章:坚持使用像jquery这样的知名库来理清所有边缘情况。