简体   繁体   中英

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. This is needed for a 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.

Developer 2 says the iframe is allowed in any context where embedded content is allowed. 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.

More information about the W3C specification can be found here: 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.

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?

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.

This is correct

Developer 2 says the IFRAME is allowed in any context where Embedded content is allowed.

Correct

Some embedded content may also be Interactive Content (eg: Audio tags), and these must be in the BODY,

Correct

however, the IFRAME we add has no content

Incorrect.

The child nodes of the iframe element provide alternative content for browsers without support for frames. This is content.

The iframe itself is a replaced element. It generates a visual UI on the page for displaying another document. 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.

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.

If we place the IFRAME without content

There is no such thing

in the HEAD will this be a violation of the specifications

Putting any iframe in the head will violate the specification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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