可能重复: 不支持
既然$.browser 正在被从jQuery中带走支持$.support,那么如何使用jQuery或普通的javascript检测IE8呢?
if ($.browser.msie && parseInt($.browser.version, 10) === 8) {
alert('IE8');
}对不起,但是HTML不适合我。所以我不能这么做
<!--[if IE 8]>
<script type="text/javascript">
ie = 8;
</script>
<![endif]-->具体来说,我希望使用画布标记来完成工作,IE8不支持画布,但jQuery.support不检测帆布支持。
发布于 2012-07-06 21:41:04
相反,测试该特性:
var el = document.createElement('canvas');
if (el.getContext && el.getContext('2d')) {
// canvas supported
}编辑:
在布兰登·布恩( Brandon )的“评论中建议的链接”( the 评论中建议的链接)中,有一个函数可以做到这一点:
function isCanvasSupported(){
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}发布于 2012-07-06 21:43:07
如果jQuery不满足您的需要,我建议使用现代派进行特征检测。
当然,另一种选择是,在不推荐jQuery之前,只使用旧版本的$.browser。它仍然工作得和以前一样好,没有人强迫你升级到最新的版本。
最后,您声明不能编辑HTML,因此不能使用条件注释。但是,值得指出的是,IE还支持相当于条件注释的Javascript。我假设您将能够使用此功能。
以下代码摘自维基百科 --根据需要对其进行调整:
<script>
/*@cc_on
@if (@_jscript_version == 10)
document.write("You are using IE10");
@elif (@_jscript_version == 9)
document.write("You are using IE9");
@elif (@_jscript_version == 5.8)
document.write("You are using IE8");
@elif (@_jscript_version == 5.7 && window.XMLHttpRequest)
document.write("You are using IE7");
@elif (@_jscript_version == 5.6 || (@_jscript_version == 5.7 && !window.XMLHttpRequest))
document.write("You are using IE6");
@elif (@_jscript_version == 5.5)
document.write("You are using IE5.5");
@else
document.write("You are using IE5 or older");
@end
@*/
</script>https://stackoverflow.com/questions/11369910
复制相似问题