如果我想重定向到我的 HTML 文件中的另一个页面,是否必须将元标记放在 head
中,或者我可以将它放在文件顶部的 DOCTYPE 之前吗?谢谢。
最佳答案
您不能将 meta
标记放在 DOCTYPE 之上。 DOCTYPE 必须始终是 HTML 文档中的第一个元素,meta
标记只能放在 head
中。
Documents must consist of the following parts, in the given order:
- Optionally, a single "BOM" (U+FEFF) character.
- Any number of comments and space characters.
- A DOCTYPE.
- Any number of comments and space characters.
- The root element, in the form of an html element.
- Any number of comments and space characters.
来源:http://www.w3.org/TR/html5/syntax.html#writing
出于这个问题的目的,规范规定文档必须以 DOCTYPE 开头,然后是根 html
元素。虽然 meta
标记可能仍然有效,但不能保证它今天仍然有效并且将来会继续有效。
关于html - 重定向到另一个页面元标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12743038/