6

我在一家公司工作,我们所有的网站目前都使用 XHTML 1.0 过渡文档类型(是的,我知道这是非常古老的学校)。我想将它们全部更改为使用 HTML5 文档类型,因为它是向后兼容的。我想要进行切换的原因之一是因为在 IE8 中,如果有人安装了开发人员工具,那么旧的 XHTML doctype 会将浏览器切换到兼容模式并将页面呈现为 IE7。通过阅读它,我被引导相信 HTML5 doctype 会将任何页面设置为以标准模式呈现,但是当我在我们的登台服务器上测试它时,这并没有发生,它仍然会切换到 IE7 呈现模式。

奇怪的是,如果我在本地保存带有 HTML5 文档类型的页面并打开它,它会以 IE8 标准模式呈现。一定有其他原因导致它陷入兼容 IE7 渲染。任何想法这可能是什么?

以下是我一直在查看的测试页面的标题:

    <!DOCTYPE html >

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>

    <title>Burton - Mens Clothing - Mens Fashion - Burton Menswear</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta name="description" content="Burton is one of the UK's leading men's clothing &amp; fashion retailers, with a range of men's clothing designed to make you look &amp; feel good. Find formal &amp; casual clothes &amp; accessories for men online at Burton menswear"/>
    <meta name="keywords" content="menswear, clothes for men, clothing for men, men clothes, men's fashion, men's wear, men's clothing online, men's clothes online, men's clothes shop, burton men's, burton menswear, burton uk, burton"/>

    <script type="text/javascript">document.getElementsByTagName('html')[0].className = 'js';</script>

    <link rel="stylesheet" type="text/css" href="http://eu.burton-menswear.com/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color2/v3/css/screen.css" />
    <link rel="stylesheet" type="text/css" href="http://eu.burton-menswear.com/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color2/v3/css/print.css" media="print"/>

    <link rel="stylesheet" type="text/css" href="http://eu.burton-menswear.com/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color2/v3/css/brand.css" />

    <!--[if lt IE 8]>
    <link rel="stylesheet" href="http://eu.burton-menswear.com/wcsstore/ConsumerDirectStorefrontAssetStore/images/colors/color2/v3/css/ie.css" type="text/css" media="screen, projection">
    <![endif]-->

    <meta http-equiv="content-language" content="en-gb" />

    <link rel="shortcut icon" type="image/x-icon" href="http://eu.burton-menswear.com/favicon.ico" />
    <link rel="search" type="application/opensearchdescription+xml" title="burton.co.uk Search"  href="http://eu.burton-menswear.com/burton-search.xml"/>
    <!-- Start Summit Tag -->
    <script type="text/javascript"> 
  var __stormJs = "t1.stormiq.com/dcv4/jslib/3286_D92B7532_4A18_46A8_864A_5FDF1DF25844.js";
</script>
    <script type="text/javascript" src="http://eu.burton-menswear.com/javascript/track.js"></script>
    <!-- End Summit Tag -->
    <!-- Start QuBit Tag -->
    <script src=//d3c3cq33003psk.cloudfront.net/opentag-31935-42109.js async defer></script>
    <!-- End QuBit Tag -->
    <link type="text/css" rel="stylesheet" href="http://reviews.br.wcstage.arcadiagroup.ltd.uk/bvstaging/static/6028-en_gb/bazaarvoice.css" ></link>

</head>
4

3 回答 3

16

IE 8 中有几个设置可以导致页面以兼容模式呈现,无论页面的 HTML 内容或 HTTP 标头如何:

  1. 页面 > 兼容性视图设置

    • 如果勾选“在兼容性视图中显示内网站点”,则 IE 将以兼容性视图呈现本地网络上的所有站点。(这在我开发过程中发生过几次。)

    • 如果选中“包括 Microsoft 更新的网站列表”,则 IE 将从 Microsoft 下载网站列表并将它们全部呈现在兼容性视图中。

    • 如果选中“在兼容性视图中显示所有网站”,那么,你可以猜到会发生什么。

  2. 工具 > Internet 选项 > 高级 > 浏览

    • 如果选中“使用兼容性视图自动从页面布局错误中恢复”,那么如果 IE 认为页面布局损坏,有时会切换到兼容性视图。

  3. 最后,如果您导航到一个页面,然后单击页面 > 兼容性视图(或单击地址栏中的兼容性视图图标),那么该页面将在兼容性视图中呈现。

因此,尽管值得放在X-UA-Compatible那里并使用像 HTML5 这样的文档类型(这样你的意图就很清楚了),但在测试时总是先检查这些设置。

于 2012-11-12T10:55:50.093 回答
8

我不确定这是否有帮助,但在IE9中,您必须使用:

<!DOCTYPE html>

和以下元标记:

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

在测试了这两者的组合之后,我发现了以下内容:

  • 无 Doctype 或 Meta Tag:
    Quirks 模式,IE 引擎 = 5

  • 仅文档类型:
    标准模式,IE 引擎 = 7

  • Doctype 和 Meta Tag
    标准模式,IE 引擎 = 9

  • 仅元标记
    标准模式,IE 引擎 = 9

如何确定模式类型和引擎:

  • document.compatMode: CSS1Compat= 标准模式,否则你处于怪癖模式

  • document.documentMode: 返回 IE 使用哪个引擎来渲染文档


笔记:

  • 通常 Doctype 必须是文件的第一行。我不确定,但我认为 XML 标记可以在它之前。如果之前有任何其他内容,您可能会破坏您的 doctype 声明:
  • 元标签必须放在<HEAD>
  • 你的帖子已经有 25 天了,所以我假设你有一个解决方案。即便如此,我不确定这些 IE9 设置是否适合您的问题。您必须检查window.document.compatModewindow.document.documentMode确定它们在 IE8 下是否可行
  • 将元标记更改为<meta http-equiv="X-UA-Compatible" content="IE=8">
  • 虽然可以只使用元标记,但我不建议在没有文档类型的情况下使用它。因为这可能会导致 XML、CSS 和脚本出现问题

我花了几个小时试图弄清楚这一点并发布了这篇文章,所以我希望有人真的能从我的研究中得到一些用处。愿源与你同在...

于 2012-12-08T12:53:55.950 回答
4

XHTML 1.0 过渡文档类型(当规范使用时,带有 URL)和<!doctype html>触发 IE 中的“标准模式”。如果这没有发生,有很多原因可能与 doctype 更改无关(并且只有在附加信息(例如 URL)可用时才能进行分析);请参阅使用 Doctype 激活浏览器模式中的IE 8 和 IE 9 复杂性

更改为<!doctype html>是没有意义的并且是一个潜在的问题,除非您实际上没有更改标记。在验证中,这是使用 doctype 的另一个原因,它会导致完全不同的分析,并且经常会出现关于在 XHTML 1.0 中有效的构造的错误消息。

于 2012-11-12T11:23:58.053 回答