如果我想重定向到我的 HTML 文件中的另一个页面,是否必须将元标记放在中,head
或者我可以将它放在文件顶部的 DOCTYPE 之前吗?谢谢你。
问问题
14885 次
5 回答
3
您不能meta
在 DOCTYPE 上方放置标签。DOCTYPE 必须始终是 HTML 文档中的第一个元素,并且meta
标签只能放在head
.
文件必须按给定顺序由以下部分组成:
- (可选)单个“BOM”(U+FEFF)字符。
- 任意数量的注释和空格字符。
- 文档类型。
- 任意数量的注释和空格字符。
- 根元素,采用 html 元素的形式。
- 任意数量的注释和空格字符。
来源:http ://www.w3.org/TR/html5/syntax.html#writing
出于这个问题的目的,规范说文档必须以 DOCTYPE 开头,然后是根html
元素。虽然meta
标签可能仍然有效,但不能保证它今天会这样做并且将来会继续这样做。
于 2012-10-05T09:09:00.917 回答
1
W3C 不赞成使用它,但他们确实在W3C上提供了一个示例:
<HEAD>
<TITLE>Don't use this!</TITLE>
<META http-equiv="refresh" content="5;http://www.example.com/newpage">
</HEAD>
<BODY>
<P>If your browser supports Refresh, you'll be transported to our
<A href="http://www.example.com/newpage">new site</A>
in 5 seconds, otherwise, select the link manually.
</BODY>
于 2012-10-05T09:10:45.417 回答
1
元标记必须在该<head></head>
部分内。之前不能添加任何东西<!DOCTYPE html>
于 2012-10-05T09:10:58.340 回答
0
GIYF:H76:使用元刷新创建即时客户端重定向
于 2012-10-05T09:12:24.503 回答
0
您应该在 HTML 页面的head部分插入以下行,将 http:example.com/ 替换为您要将查看者重定向到的实际网页:
< meta http-equiv="刷新" content="2;url= http://example.com/ " />
这是一个在典型 HTML 页面中插入正确行的示例。请注意,它位于标题标签之上。
<html>
<head>
<meta http-equiv="refresh" content="2;url=http://example.com" />
<title>Page Moved</title>
</head>
<body>
This page has moved. Click <a href="http://www.example.com">here</a> to go to the new page.
</body>
</html>
于 2017-09-16T07:09:27.887 回答