<script type="text/javascript">
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ieversion>=8)
document.write("You're using IE8 or above")
else if (ieversion>=7)
document.write("You're using IE7.x")
else if (ieversion>=6)
document.write("You're using IE6.x")
else if (ieversion>=5)
document.write("You're using IE5.x")
}
else
document.write("n/a")
</script>
嗅探用户代理不是一个“安全”的解决方案。
我更喜欢 Dean Edwards 的方法
var isMSIE = /*@cc_on!@*/false;
(更多信息:http://dean.edwards.name/weblog/2007/03/sniff/ )
条件编译在 IE11 中已被移除
或者直接使用已经构建好的东西,不要重新编写它
if ($.browser.ie) { … }
$.browser 现在不再受 JQuery 支持
使用条件注释要容易得多,不是吗?
条件注释的问题在于 IE 10 不再支持它们
但条件注释在 IE 10 中不起作用
此代码不适用于 IE11,您能否修改 MSIE 以检测 IE11,请帮忙。
您可以尝试这个
谢谢!document.documentMode 非常有效!!:)
不客气!:)
Nicola 做得好。我不知道这是一个特定的 IE 属性:https://w3schools.org.cn/jsref/prop_doc_documentmode.asp
你能提供一个 CSS 版本吗?