如何强制 Internet Explorer 以标准模式而不是怪异模式呈现?

发布于 2024-10-24 09:20:53 字数 508 浏览 2 评论 0原文

我正在编写一个在 IE7 标准模式和 IE8 标准模式下运行良好的前端。

当我启动 Internet Explorer 并加载页面时,IE7 和 IE8 都会直接进入 Quirks 模式。如何强制 IE7 和 IE8 始终以标准模式加载页面?

到目前为止我还没有添加特殊的元标签。

感谢您帮助我

编辑:我的文档类型和头部目前如下所示:

<!DOCTYPE html> 
<html lang="de"> 
<head> 
    <title>...</title> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8" />
    <script src="js/html5.js"></script> 

    (...)
</head>

I am coding a Frontend which works well in IE7 Standards Mode and IE8 Standards Mode.

When I start up Internet Explorer and load the page both IE7 and IE8 go to Quirks Mode directly. How can I force both IE7 and IE8 to always load the page in Standards Mode?

I have no special meta tags added so far.

Thanks for helping me out

Edit: My doctype and head looks as follows at the moment:

<!DOCTYPE html> 
<html lang="de"> 
<head> 
    <title>...</title> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="utf-8" />
    <script src="js/html5.js"></script> 

    (...)
</head>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

甜心小果奶 2024-10-31 09:20:53

这是绝对确定的方法:

<!doctype html> <!-- html5 -->
<html lang="en"> <!-- lang="xx" is allowed, but NO xmlns="http://www.w3.org/1999/xhtml", lang:xml="", and so on -->
<head>
<meta http-equiv="x-ua-compatible" content="IE=Edge"/> 
<!-- as the **very** first line just after head-->
..
</head>

原因:
每当 IE 遇到任何冲突时,它都会返回“IE 7 标准模式”,忽略 x-ua 兼容。

(我知道这是一个非常古老的问题的答案,但我自己也一直在努力解决这个问题,上面的方案是正确的答案。它一直有效,每次)

This is the way to be absolutely certain :

<!doctype html> <!-- html5 -->
<html lang="en"> <!-- lang="xx" is allowed, but NO xmlns="http://www.w3.org/1999/xhtml", lang:xml="", and so on -->
<head>
<meta http-equiv="x-ua-compatible" content="IE=Edge"/> 
<!-- as the **very** first line just after head-->
..
</head>

Reason :
Whenever IE meets anything that conflicts, it turns back to "IE 7 standards mode", ignoring the x-ua-compatible.

(I know this is an answer to a very old question, but I have struggled with this myself, and above scheme is the correct answer. It works all the way, everytime)

带刺的爱情 2024-10-31 09:20:53

可悲的是,他们希望我们使用标签来让他们的浏览器知道该怎么做。看看这个文档,它告诉我们使用:

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

应该可以。

Sadly, they want us to use a tag to let their browser know what to do. Look at this documentation, it tell us to use:

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

and it should do.

奢望 2024-10-31 09:20:53
  1. 在页面开头使用 html5 文档类型。

  2. 强制 IE 使用最新的渲染模式

  3. 如果您的目标浏览器是 ie8,请检查您的兼容设置
    在 IE8 中

我详细介绍了此内容

  1. Using html5 doctype at the beginning of the page.

    <!DOCTYPE html>

  2. Force IE to use the latest render mode

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

  3. If your target browser is ie8, then check your compatible settings
    in IE8

I blog this in details

夜声 2024-10-31 09:20:53

添加正确的文档类型声明并避免 XML 序言应该足以避免怪异模式

Adding the correct doctype declaration and avoiding the XML prolog should be enough to avoid quirks mode.

┊风居住的梦幻卍 2024-10-31 09:20:53

我知道这个问题是两年前提出的,但还没有人提到过。

最好的方法是使用 http 标头

将元标记添加到标头并不总是有效,因为 IE 可能在读取之前就已经确定了模式。确保 IE 始终使用标准模式的最佳方法是使用自定义 http 标头。

标头:

name: X-UA-Compatible  
value: IE=edge

例如,在 .NET 应用程序中,您可以将其放入 web.config 文件中。

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>

I know this question was asked over 2 years ago but no one has mentioned this yet.

The best method is to use a http header

Adding the meta tag to the head doesn't always work because IE might have determined the mode before it's read. The best way to make sure IE always uses standards mode is to use a custom http header.

Header:

name: X-UA-Compatible  
value: IE=edge

For example in a .NET application you could put this in the web.config file.

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=edge" />
      </customHeaders>
    </httpProtocol>
</system.webServer>
流年已逝 2024-10-31 09:20:53

HTML5 Doctype 可能会导致您在使用旧版浏览器时出现问题。它也可能与 HTML5 shiv 相关的一些时髦的东西有关。

您可以尝试切换到一种 XHTML 文档类型并相应地更改您的标记,至少暂时如此。这可能会让您缩小问题范围。

当这些 IE 切换到怪异模式时,您的设计是否会被破坏?如果是您的 CSS 导致内容显示异常,那么可能值得对 CSS 进行处理,以便即使浏览器切换模式,网站看起来也一样。

It's possible that the HTML5 Doctype is causing you problems with those older browsers. It could also be down to something funky related to the HTML5 shiv.

You could try switching to one of the XHTML doctypes and changing your markup accordingly, at least temporarily. This might allow you to narrow the problem down.

Is your design breaking when those IEs switch to quirks mode? If it's your CSS causing things to display strangely, it might be worth working on the CSS so the site looks the same even when the browsers switch modes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文