我有一个jQuery代码,它可以很好地工作在Chrome/Mozilla上,但不能用于IE。
if ($("html").hasClass("ie")) {
$(function(){
$('.green-column, .red-column, .grey-column').click(function() {
alert ($(this).attr("data-type"));
});
});
}
else {
$(function(){
$('.green-column, .red-column, .grey-column').click(function() {
$("<div title='Selected Task is:'>" + $(this).attr("data-type") + "</div>").dialog({
modal: true,
resizable: false,
buttons: [
{
text: "OK",
click: function() { $( this ).dialog( "close" ); }
}
]
});
});
});
}
</script>
<!--[if IE 7]> <html lang="en-us" class="ie"> <![endif]-->
<!--[if IE 8]> <html lang="en-us" class="ie"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us" class="ie"> <!--<![endif]-->因此,我计划为IE9/IE10使用一个警告,但我无法区分这两种浏览器。谁能告诉我如何在jQuery/HTML中识别IE9/IE10?
发布于 2013-09-18 20:03:56
可以在不使用库或条件编译的情况下实现:
if (document.addEventListener) {
alert("IE9 or greater");
}
if (window.requestAnimationFrame) {
alert("IE10 or greater");
}发布于 2013-03-27 19:23:20
就像这样做
if ($.browser.msie && parseInt($.browser.version, 10) > 8) {
alert('IE9 or IE10');
} else {
alert('Non IE9 or IE10');
}这应该适用于1.9以下的jQuery版本。如果您使用1.9+,请阅读此thread或考虑使用modernizr。
发布于 2013-03-27 19:28:35
检测当前活动的IE版本(可能是模拟的)的唯一可靠方法是结合使用conditional compilation和document.documentMode检查。
条件编译是可选的,但它允许您永远不为非IE浏览器运行IE检测脚本。
例如:
if (/*@cc_on !@*/false && (
document.documentMode === 9 || document.documentMode === 10)
) {
// IE 9 or 10 (not 8 or 11!)
document.documentElement.className += ' ie9 ie10';
}前面的代码对于微型程序来说是不安全的。如果你打算缩小你的代码,把条件编译的东西放在一个字符串中,然后eval它:
if (eval('/*@cc_on !@*/false') && ( ... )) { ... }https://stackoverflow.com/questions/15657614
复制相似问题