简体   繁体   English

如何在IE9中检测浏览器模式是否在“Internet Explorer 9兼容性视图”中?

[英]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视为浏览器,则可以放心地假设您处于兼容模式。

documentMode explaination documentMode解释

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.

相关问题 IE9和IE9兼容性视图浏览器模式之间的区别 - Difference between IE9 and IE9 Compatibility View browser mode 带有javascript的网站无法在IE9中使用,但只能在IE9的兼容模式下使用-如何强制兼容视图? - Website with javascript doesn't work in IE9 but in IE9's compatibility mode - how to force compatibility view? 浏览器支持Internet Explorer 10-兼容模式 - Browser support Internet Explorer 10 - Compatibility Mode 当浏览器模式为IE9时,如何从JS检测IE10? - How can I detect IE10 from JS when browser mode is IE9? JavaScript:如果 IE9 处于 IE7 或 IE8 兼容模式,我可以检测到它吗? - JavaScript: Can I detect IE9 if it's in IE7 or IE8 compatibility mode? 在perl中检测浏览器,如何检查浏览器是否为perl中的Internet Explorer(IE) - detect browser in perl,how to check if the browser is internet explorer(IE) in perl 如何检测IE8兼容模式 - How to detect IE8 compatibility mode 如何在Internet Explorer 10+中检测点击次数 - How do I detect the number of clicks in Internet Explorer 10+ 如何检测 IE 和 Edge 浏览器? - How do I detect IE and Edge browser? 如何在Javascript中以编程方式打开IE9兼容性视图 - How to turn on IE9 Compatibility View programmatically in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM