简体   繁体   English

根据W3C,头标记中是否允许使用iframe标记?

[英]Is the iframe tag allowed in the head tag according to the W3C?

I am in the middle of a discussion with two developers about placing an <iframe> in the <head> of an HTML page. 我正在与两位开发人员讨论如何在HTML页面的<head>中放置<iframe> This is needed for a TAG. 这是TAG所必需的。

According to developer 1, the tag may not be placed in the header because the tag creates an iframe to load another tag, and iframes are flow content and must be placed in the <body> according to the W3C specifications for HTML 5.1. 根据开发人员1,标签可能不会放在标头中,因为标签会创建一个iframe来加载另一个标签,而iframe是流内容,必须根据HTML 5.1的W3C规范放在<body>

Developer 2 says the iframe is allowed in any context where embedded content is allowed. 开发人员2表示,在允许嵌入内容的任何环境中都允许使用iframe。 Some embedded content may also be interactive content (eg audio tags), and these must be in the body; 一些嵌入的内容也可以是交互式内容(例如音频标签),并且这些内容必须在体内; however, the iframe we add has no content and is not interactive, so based on his understanding of the spec, it may show up anywhere in the document. 但是,我们添加的iframe没有内容且不是交互式的,因此根据他对规范的理解,它可能会出现在文档的任何位置。

More information about the W3C specification can be found here: http://www.w3.org/TR/html5/dom.html#kinds-of-content 有关W3C规范的更多信息,请访问: http//www.w3.org/TR/html5/dom.html#kinds-of-content

The W3C validator does not throw a error or warning with an iframe in the head, but this is not enough for developer 1. W3C验证器不会在头部出现iframe错误或警告,但这对于开发人员1来说还不够。

Mu question is simple: if we place the iframe without content in the head, will this be a violation of the specifications or does the specification leave room for interpretation like developer 2 says? 问题很简单:如果我们将没有内容的iframe放在头部,这是否违反了规范,或者规范是否像开发人员2所说的那样留下了解释空间?

According to developer 1 the tag may not be placed in the header because the tag creates an IFRAME to load another tag and IFRAME's are flow content an must be placed in the BODY according to the W3C specifications for HTML 5.1. 根据开发人员1,标签可能不会放在标头中,因为标签会创建一个IFRAME来加载另一个标签,而IFRAME是必须根据HTML 5.1的W3C规范放在BODY中的流内容。

This is correct 这是对的

Developer 2 says the IFRAME is allowed in any context where Embedded content is allowed. 开发人员2表示允许在允许嵌入式内容的任何环境中使用IFRAME。

Correct 正确

Some embedded content may also be Interactive Content (eg: Audio tags), and these must be in the BODY, 某些嵌入内容也可能是交互式内容(例如:音频标签),这些内容必须位于BODY中,

Correct 正确

however, the IFRAME we add has no content 但是,我们添加的IFRAME没有内容

Incorrect. 不正确。

The child nodes of the iframe element provide alternative content for browsers without support for frames. iframe元素的子节点为不支持框架的浏览器提供替代内容。 This is content. 这是内容。

The iframe itself is a replaced element. iframe本身是一个被替换的元素。 It generates a visual UI on the page for displaying another document. 它在页面上生成可视UI以显示另一个文档。 This is content. 这是内容。

and is not interactive, 而且不是互动的,

The specification explicitly lists it as being interactive content . 规范明确将其列为交互式内容

so based on his understanding of the spec, it may show up anywhere in the document. 所以基于他对规范的理解,它可能会出现在文档的任何地方。

Incorrect. 不正确。

The W3C validator does not throw a error or warning, but this is not enough for developer 1. W3C验证器不会抛出错误或警告,但这对于开发人员1来说还不够。

An iframe, not being allowed in the head, will implicitly end the head element and start the body element, so you will only get an error if you follow it with content that is allowed only in the head or an explicit head end tag or body start tag. 不允许在头部中使用的iframe将隐式结束head元素并启动body元素,因此如果您使用仅在头部或显式头端标记或正文中允许的内容,则只会出现错误开始标记。

If we place the IFRAME without content 如果我们放置没有内容的IFRAME

There is no such thing 哪有这回事

in the HEAD will this be a violation of the specifications 在HEAD中这将违反规范

Putting any iframe in the head will violate the specification 将任何iframe放在头部都会违反规范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM