javascript - 如何模拟客户的IE兼容性 View 设置?

标签 javascript internet-explorer-10 ie-compatibility-mode

更新:主要问题是,尽管有适当的 doctype 和 x-ua 兼容的元标记,是否有任何因素会导致 IE10 特别以 IE5 怪异模式(而不是一般的兼容模式)呈现页面? (需要明确的是,我们不希望页面以 IE5 怪癖呈现,我们希望它以完整的 IE10 标准呈现。)

<小时/>

我们的页面正在为一位客户以 IE5 怪异模式呈现,导致呈现失败。我可以使用开发工具强制 IE 进入相同的模式并复制相同的故障,但为什么这种情况首先会发生在他(而且只有他)身上?这可能是他的环境中的某些东西,我可以在我这边模拟它吗?客户使用的是IE10。

我们正在使用:

<!DOCTYPE html>

和:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

我们还将添加一个 HTTP 响应 header :

X-UA-Compatible: IE=edge,chrome=1

但是我们无法验证此修复,因为它在我们自己的 IE10 实例中运行良好。

最佳答案

从此链接:http://blogs.msdn.com/b/deviations/archive/2009/05/07/how-to-enable-ie-8-compatibility-view-for-your-whole-web-site-or-for-specific-web-site-directories.aspx

The question many customers asked is ”How can I force the client browser to use the Compatibility View when they visit our site? So that the customer doesn’t have to activate it on the client side.”

Web Developers and Site Administrators can configure IIS and their sites to tell Internet Explorer 8 to automatically Emulate Internet Explorer 7 when they visit their site or just specific WebPages.

This is done by adding a custom HTTP Header to the IIS and the website web.config or to add a meta tag to specific pages. The HTTP Header is interpreted by the Internet Explorer 8 which will activate the compatibility view. All other browsers will simply ignore this custom HTTP Header.

X-UA-Compatible: IE=EmulateIE7

这是为了强制在兼容模式下渲染。

如果您想在兼容模式下“模拟”浏览器,用户 RocketHazmat 在评论中提到了该怎么做(使用工具 > 设置)。

您可以通过以下两个博客来熟悉该属性以及IE8和IE9的兼容性 View 模式: 兼容性 View 简介:http://blogs.msdn.com/b/ie/archive/2008/08/27/introducing-compatibility-view.aspx 。 介绍 IE9 的用户代理字符串:http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx .

如果您想“检测”IE 兼容性 View 模式:

我发现这个答案很有趣:JavaScript: Can I detect IE9 if it's in IE7 or IE8 compatibility mode? (document.documentMode是最好的方法)。主题on stackoverflow from a google search .

从此链接:http://social.msdn.microsoft.com/Forums/vstudio/en-US/ae715fd2-1ddd-46f7-8c26-9aed6b2103f1/how-to-detect-compatibility-mode-in-ie-any-version

After research, we can find that the values to the User Agent String under different browse modes are:

  • IE7: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1;...)
  • IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;...)
  • IE8 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0;...)
  • IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
  • IE9 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0;...)

Note that some irrelevant values in the strings are ignored, we only need to focus on some critical values which can be combined to decide the browse mode, like MSIE version NO. and Trident Mode NO..

Here comes the final solution:

    var agentStr = navigator.userAgent;
     var mode;
     if (agentStr.indexOf("Trident/5.0") > -1) {
         if (agentStr.indexOf("MSIE 7.0") > -1)
             mode = "IE9 Compatibility View";
         else
             mode = "IE9";
     }
     else if (agentStr.indexOf("Trident/4.0") > -1) {
         if (agentStr.indexOf("MSIE 7.0") > -1)
             mode = "IE8 Compatibility View";
         else
             mode = "IE8";
     }
     else
         mode = "IE7";

     document.title = "Browser Mode:\t" + mode;
     //document.write(navigator.userAgent);

其他内容:stackoverflow.com/questions/11865188/does-the-windows-8-internet-explorer-10-still-have-quirksmode#11865561,他们解释了 2 个 IE10 怪癖模式。与你的情况有关。希望对您有所帮助。

关于javascript - 如何模拟客户的IE兼容性 View 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17977318/

相关文章:

JavaScript 存在较长 URL 和特殊字符的问题

javascript - 观察 Html 属性的 Angular 变化

asp.net-mvc-4 - IE 10 Windows 身份验证中的异步 KendoUI 上传

javascript - 如何从包含 onclick 事件的文本中删除突出显示?

javascript - 是否可以覆盖 http-equiv ="X-UA-Compatible"内容 ="IE=7"

javascript - 如何分离对象内的对象

javascript - 尝试使用 Node 获取sqlite数据

IE 10 中的 javascript 事件似乎对 pageX/Y 具有错误的值

html - 如何在IE9兼容模式下使列宽适合其内容?

javascript - 使用 IE 10 兼容模式使用 Mxgraph 旋转单元格