[英]How do I detect if the Browser mode is in “Internet Explorer 9 compatibility View” in IE9?
I use javascript script to align certain elements using offsets. 我使用javascript脚本使用偏移对齐某些元素。 Offsets are calculated depending on browser type because they behave differently.
根据浏览器类型计算偏移量,因为它们的行为不同。 In IE9, getting child elements in the DOM or calculating certain offsets, the behavior is different if IE9 is in IE9 browser mode or IE9 compatible view browser mode.
在IE9中,获取DOM中的子元素或计算某些偏移量,如果IE9处于IE9浏览器模式或IE9兼容视图浏览器模式,则行为会有所不同。
How do I detect if the Browser mode is in "Internet Explorer 9 compatibility View"? 如何检测浏览器模式是否在“Internet Explorer 9兼容性视图”中? This mode is set by the user in developer tools (F12) Browser Mode menu option.
此模式由用户在开发人员工具(F12)浏览器模式菜单选项中设置。
Pretty sure, I'm running Linux and my virtual image just broke: 很确定,我正在运行Linux并且我的虚拟映像刚刚破坏:
if (document.all && document.documentMode === 8 && !document.addEventListener) {
// IE9/IE10 in compatibility mode as IE8
}
On UA: 在UA上:
https://stackoverflow.com/a/12183662/887539 https://stackoverflow.com/a/12183662/887539
I can't remember where I got this code, but basically IE8 and up have a property on the document called "documentMode". 我不记得我在哪里得到这段代码,但基本上IE8及其上的文件属性名为“documentMode”。 If that exists, but you're seeing IE7 as the browser, you can safely assume that you are in compatibility mode.
如果存在,但您将IE7视为浏览器,则可以放心地假设您处于兼容模式。
It is possible, user agent string is different for IE9 when being run in IE7 compatibility mode, so this would be one of the best ways to find the difference between different IE versions. 在IE7兼容模式下运行时,用户代理字符串可能与IE9不同,因此这将是找到不同IE版本之间差异的最佳方法之一。
You can read more about this here: http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx 你可以在这里阅读更多相关信息: http : //blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.