Html 为什么 IE9 在我的网站上切换到兼容模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3726357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does IE9 switch to compatibility mode on my website?
提问by René
I have just installed IE9 beta and on a specific site I created (HTML5) IE9 jumps to compatibility mode unless I manually tell it not to. I have tried removing several parts of the website but no change. Including removing all CSS includes. On some other website of me it goes just fine.
我刚刚安装了 IE9 测试版,并且在我创建的特定站点上 (HTML5) IE9 会跳转到兼容模式,除非我手动告诉它不要这样做。我曾尝试删除网站的几个部分,但没有任何变化。包括删除所有 CSS 包含。在我的其他一些网站上,它运行得很好。
Also, don't set it manually because then IE9 remembers the user setting and you can't turn it back to automatic (or at least I haven't found how, not even via private browsing and emptying cache)
另外,不要手动设置它,因为 IE9 会记住用户设置并且您无法将其恢复为自动(或者至少我还没有找到方法,甚至没有通过隐私浏览和清空缓存)
Anyway. The site where it jumps to compatibility mode: http://alliancesatwar.com/guide/
One where it renders correct: http://geuze.name/basement/(I can't post more than 1 hyperlink)
反正。它跳转到兼容模式的站点:http: //alliancesatwar.com/guide/
一个正确呈现的站点:http: //geuze.name/basement/(我不能发布超过 1 个超链接)
Both use the same doctype
and all. Those sites have a lot in common(apart from appearance) using the same basic template(encoding, meta tags, doctype and the same javascript)
两者都使用相同doctype
和全部。这些网站有很多共同点(除了外观)使用相同的基本模板(编码、元标记、文档类型和相同的 javascript)
It would be great if someone has an answer for me! An HTML5 website that renders in IE7-mode is pretty... lame.
如果有人为我解答就太好了!以 IE7 模式呈现的 HTML5 网站非常......蹩脚。
回答by bobince
Works in IE9 documentMode for me.
对我来说在 IE9 文档模式下工作。
Without a X-UA-Compatible
header/meta to set an explicit documentMode, you'll get a mode based on:
如果没有X-UA-Compatible
标题/元来设置显式文档模式,您将获得基于以下内容的模式:
- whether the user has clicked the ‘compatibility view' button in that domain before;
- perhaps also whether this has happened automatically due to some other content on the site causing IE8/9's renderer to crash and fall back to the old renderer;
- whether the user has opted to put all sites in compatibility view by default;
- whether IE thinks the site is on your intranet and so defaults to compatibility view;
- whether the site in question is in Microsoft's own list of websites that require compatibility view.
- 用户之前是否点击过该域中的“兼容性视图”按钮;
- 也许这是否是由于网站上的其他一些内容导致 IE8/9 的渲染器崩溃并回退到旧渲染器而自动发生的;
- 用户是否默认选择将所有站点置于兼容性视图中;
- IE 是否认为该站点在您的内部网上,因此默认为兼容性视图;
- 有问题的站点是否在 Microsoft 自己的需要兼容性视图的网站列表中。
You can change these settings from ‘Tools -> Compatibility view settings' from the IE menu. Of course that menu is now sneakily hidden, so you won't see it until you press Alt.
您可以从 IE 菜单的“工具 -> 兼容性视图设置”更改这些设置。当然,该菜单现在被偷偷地隐藏了,所以你在按下 Alt 之前不会看到它。
As a site author, if you're confident that your site complies to standards (renders well in other browsers, and uses feature-sniffing to decide what browser workarounds to use), I suggest using:
作为网站作者,如果您确信自己的网站符合标准(在其他浏览器中呈现良好,并使用功能嗅探来决定使用哪些浏览器变通方法),我建议使用:
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
or the HTTP header:
或 HTTP 标头:
X-UA-Compatible: IE=Edge
to get the latest renderer whatever IE version is in use.
获取最新的渲染器,无论使用的是什么 IE 版本。
回答by pkario
I put
我放
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
first thing after
之后的第一件事
<head>
(I read it somewhere, I can't recall)
(在某处看过,记不清了)
I could not believe it did work!!
我简直不敢相信它确实有效!!
回答by Delan Azabani
To force IE to render in IE9 standards mode you should use
要强制 IE 在 IE9 标准模式下呈现,您应该使用
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Some conditions may cause IE9 to jump down into the compatibility modes. By default this can occur on intranet sites.
某些情况可能会导致 IE9 跳转到兼容模式。默认情况下,这可能发生在 Intranet 站点上。
回答by Mike Gledhill
I've posted this comment on a seperate StackOverflow thread, but thought it was worth repeating here:
我已经在一个单独的 StackOverflow 线程上发布了这条评论,但认为值得在这里重复:
For our in-house ASP.Net app, adding the "X-UA-Compatible" tag on the web page, in the web.config or in the code-behind made absolutely no difference.
对于我们的内部 ASP.Net 应用程序,在网页、web.config 或代码隐藏中添加“X-UA-Compatible”标签完全没有区别。
The onlything that worked for us was to manually turn off this setting in IE8:
该只为我们工作的事情是手动关闭此设置在IE8:
(Sigh.)
(叹。)
This problem only seems to happen with IE8 & IE9 on intranet sites. External websites will work fine and use the correct version of IE8/9, but for internal websites, IE9 suddenly decides it's actually IE7, and doesn't have any HTML 5 support.
这个问题似乎只发生在 Intranet 站点上的 IE8 和 IE9 上。外部网站可以正常工作并使用正确版本的 IE8/9,但对于内部网站,IE9 突然决定它实际上是 IE7,并且没有任何 HTML 5 支持。
No, I don't quite understand this logic either.
不,我也不太明白这个逻辑。
My reluctant solution has been to testwhether the browser has HTML 5 support (by creating a canvas, and testing if it's valid), and displaying this message to the user if it's not valid:
我不情愿的解决方案是测试浏览器是否支持 HTML 5(通过创建画布并测试它是否有效),如果无效则向用户显示此消息:
It's not particularly user-friendly, but getting the user to turn off this annoying setting seems to be the only way to let them run in-house HTML 5 web apps properly.
它不是特别用户友好,但让用户关闭这个烦人的设置似乎是让他们正确运行内部 HTML 5 Web 应用程序的唯一方法。
Or get the users to use Chrome. ;-)
或者让用户使用 Chrome。;-)
回答by uknowit2
As an aside on more modern websites, if you are using conditional statements on your html tag as per boilerplate, this will for some reason cause ie9 to default to compatibility mode. The fix here is to move your conditional statements off the html tag and add them to the body tag, in other words out of the head section. That way you can still use those classes in your style sheet to target older browsers.
顺便说一句,在更现代的网站上,如果您按照样板在 html 标签上使用条件语句,这将出于某种原因导致 ie9 默认为兼容模式。此处的解决方法是将您的条件语句从 html 标记中移出并将它们添加到 body 标记中,换句话说,将它们添加到 head 部分之外。这样,您仍然可以在样式表中使用这些类来定位较旧的浏览器。
回答by Rob at TVSeries.com
The site at http://www.HTML-5.com/index.htmldoes have the X-UA-Compatible meta tag but still goes into Compatibility View as indicated by the "torn page" icon in the address bar. How do you get the menu option to force IE 9 (Final Version 9.0.8112.16421) to render a page in Standards Mode? I tried right clicking that torn page icon as well as the "Alt" key trick to display the additional menu options mentioned by Rene Geuze, but those didn't work.
http://www.HTML-5.com/index.html上的站点确实具有 X-UA-Compatible 元标记,但仍会进入兼容性视图,如地址栏中的“撕裂页面”图标所示。如何获得强制 IE 9(最终版本 9.0.8112.16421)在标准模式下呈现页面的菜单选项?我尝试右键单击那个撕裂的页面图标以及“Alt”键技巧来显示 Rene Geuze 提到的其他菜单选项,但这些都不起作用。
回答by Abderrazak BOUADMA
I recently had to resolve this issue and here's what I did :
我最近不得不解决这个问题,这就是我所做的:
First of all, this solution is around tuning Apache server.
首先,这个解决方案是围绕着调整 Apache 服务器的。
Second main think is that there's a bug in the IE9 which means that the meta tag will not work, instead of this solution try this
第二个主要想法是 IE9 中有一个错误,这意味着元标记不起作用,而不是这个解决方案试试这个
- find/open your httpd.conf
uncomment/or add the following line
LoadModule headers_module modules/mod_headers.so
add the following lines
<IfModule headers_module> Header set X-UA-Compatible: IE=EmulateIE8 </IfModule>
save/restart your Apache server,
- browse to your page with IE9, use tools like wiresharkor fiddleror use IE developer tools to check the header is there
回答by Yi Jiang
Looks fine to me:
对我来说看起来不错:
You're sure you didn't on the settings globally or something? This is a clean installation of the beta on Windows 7. The developer tools report that the page is defaulting to IE9 Standard Mode.
您确定您没有进行全局设置或其他设置吗?这是 Windows 7 上测试版的全新安装。开发人员工具报告该页面默认为 IE9 标准模式。