我知道下面的代码将适用于IE8及其较低版本。
<!--[if lte IE 8]>
Display an image file
<![endif]-->
是否有类似的语法来识别IE 11和其他浏览器,如Firefox,chrome,..。
下面是我的原型。
<!--[if IE 11 & other_browsers]>
Display Chart plugin here
<![endif]-->
我需要这个在我的网页上显示一个图表。IE 11和其他浏览器(Firefox,chrome,..)支持它。但IE8并不支持。所以我计划在IE11和其他浏览器上显示这张图表。较低版本的IE将显示一个图像。
对于这一要求,我正在尝试条件注释。
发布于 2015-12-23 12:51:01
你可以通过下面的代码获得ie版本-
document.documentMode
这样你就可以像
if (document.documentMode==11) {
// do something
}
而对于其他浏览器,则提供document.documentMode==undefined
因此,您可以按以下方式创建此条件:
if (document.documentMode==11 || document.documentMode==undefined) {
// do something
}
发布于 2015-12-23 12:42:32
发布于 2015-12-23 13:07:04
有一个StackOverflow邮政回答你的问题:
在窗口中使用!(window.ActiveXObject) && "ActiveXObject“显式地检测IE11。
编辑:您可以按以下方式使用上述测试:
var isMSIE11 = !(window.ActiveXObject) && "ActiveXObject"
if(isMSIE11) {
//use JS or JQuery to add chart
$('#mydiv').....
}
它只适用于IE11。但是,根据您的用例,您可能需要进行特征检测而不是浏览器检测。根据这篇MSDN文章,浏览器检测有几个缺点:
像现代化者这样的框架就是为此而构建的。
https://stackoverflow.com/questions/34435931
复制相似问题