【发布时间】:2015-10-15 09:23:51
【问题描述】:
有什么方法可以实用地检测 Internet Explorer 11 企业模式?
在 csharp 或 javascript/jquery 中,实际上是指在服务器端。
后续话题还没有定论
IE 11 - Is there a way to check then enable / disable enterprise mode?
【问题讨论】:
标签: javascript c# internet-explorer-11
有什么方法可以实用地检测 Internet Explorer 11 企业模式?
在 csharp 或 javascript/jquery 中,实际上是指在服务器端。
后续话题还没有定论
IE 11 - Is there a way to check then enable / disable enterprise mode?
【问题讨论】:
标签: javascript c# internet-explorer-11
您可以验证用户代理字符串
使用 Javascript 获取用户代理字符串:navigator.userAgent;
对于桌面上的 IE11 企业模式,用户代理字符串将为
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Tablet PC 2.0)
参考https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
【讨论】:
发送 X-UA-Compatible HTTP 标头或在页面的 HEAD 中使用 META 标记将使 IE 进入兼容模式。所以不这样做会让它在正常模式下运行。
如果您想测试浏览器是否兼容,我会编写一个 jQuery AJAX 调用,尝试使用在旧版 IE 中无法使用的 JavaScript 函数,并在 try catch 中将结果发布到您的应用程序。
例如 trim() doesn't work in IE8
var str = " Hello World! ";
var a = (str.trim());
if(a == "Hello World!"){
//Ajax Post true
} else {
//Ajax Post false
}
这应该可以工作,因为如果企业模式被激活,它将在 IE8 中工作
【讨论】: