如何处理 HTML5 中未验证的元元素?

发布于 2024-09-14 14:54:49 字数 917 浏览 2 评论 0原文

在 HTML5 中,某些元元素尚未验证(还?),例如:

<meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1">
<meta http-equiv="imagetoolbar" content="no">

条件注释是否是适当的解决方案。元元素仍然会按预期工作吗?

<!--[if IE]><meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1"><![endif]-->
<!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no"><![endif]-->

使用 .htaccess 文件而不是元元素(不幸的是并不总是可能),这是正确的方法吗?

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
  # BrowserMatch MSIE ie OR?
    BrowserMatch MSIE emulate_ie7
  # Header set X-UA-Compatible "IE=EmulateIE7" env=ie OR?
    Header set X-UA-Compatible "IE=EmulateIE7" env=emulate_ie7
    BrowserMatch chromeframe gcf
    Header append X-UA-Compatible "chrome=1" env=gcf
  </IfModule>
</IfModule>

谢谢!

In HTML5, some meta elements do not validate (yet?) like:

<meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1">
<meta http-equiv="imagetoolbar" content="no">

Are Conditional Comments an appropriate solution here resp. will meta elements still work as expected?

<!--[if IE]><meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1"><![endif]-->
<!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no"><![endif]-->

Using a .htaccess file instead of meta elements (not always possible unfortunately), would this be the right way to go?

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
  # BrowserMatch MSIE ie OR?
    BrowserMatch MSIE emulate_ie7
  # Header set X-UA-Compatible "IE=EmulateIE7" env=ie OR?
    Header set X-UA-Compatible "IE=EmulateIE7" env=emulate_ie7
    BrowserMatch chromeframe gcf
    Header append X-UA-Compatible "chrome=1" env=gcf
  </IfModule>
</IfModule>

Thanks!

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

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

发布评论

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

评论(2

故事灯 2024-09-21 14:54:49

就我个人而言,对于“x-ua-兼容”标签,我选择了 .htaccess 指令。我遵循 html5boilerplate 模板:

# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------

# Force the latest IE version, in various cases when it may fall back to IE7 mode
#  github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>

<IfModule mod_headers.c>
# Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
#   We need to inform proxies that content changes based on UA
  Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare
</IfModule>

Personally for the "x-ua-compatible" tag, i went for the .htaccess directive. I followed the html5boilerplate template:

# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------

# Force the latest IE version, in various cases when it may fall back to IE7 mode
#  github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk

<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    BrowserMatch MSIE ie
    Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  </IfModule>
</IfModule>

<IfModule mod_headers.c>
# Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
#   We need to inform proxies that content changes based on UA
  Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare
</IfModule>
孤檠 2024-09-21 14:54:49

您可以注册其他pragma指令

在某些条件下,预定义的 pragma 指令集的扩展可以在 WHATWG Wiki PragmaExtensions 中注册页面

然后,一致性检查员需要识别它们:

一致性检查人员必须使用 WHATWG Wiki PragmaExtensions 页面上给出的信息来确定是否允许某个值:本规范中定义的值或上述页面中列出的值必须被接受,而本规范或未列出的值则必须被接受。上述页面上的内容必须被视为无效而被拒绝。

但这可能是一项艰苦的工作,不知道之前是否有任何原因没有列出这些标头,但我想如果您尝试一下,您就会发现:)

根据 MS 文档,根据您使用的 Apache 版本,可能会有一些变化,但最好的检查方法可能是尝试一下。

You can register additional pragma directives:

Extensions to the predefined set of pragma directives may, under certain conditions, be registered in the WHATWG Wiki PragmaExtensions page.

Conformance checkers are then required to recognise them:

Conformance checkers must use the information given on the WHATWG Wiki PragmaExtensions page to establish if a value is allowed or not: values defined in this specification or listed on the aforementioned page must be accepted, whereas values not listed in either this specification or on the aforementioned page must be rejected as invalid.

That may be hard work though, don't know if there's any reason why these headers haven't been listed before but I guess you'll find out if you try it :)

Your .htaccess looks OK according to the MS docs, there may be some variations depending on what version of Apache you're on, but probably the best way to check is to try it and see.

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