2012-10-05 33 views

回答

3

您不能將meta標籤放在DOCTYPE上方。 DOCTYPE必須始終是HTML文檔中的第一個元素,meta標籤必須只能放在head中。

文檔必須由以下部分組成,在給定的順序:

  • 任選地,一個單一的 「BOM」(U + FEFF)字符。
  • 任意數量的評論和空格字符。
  • DOCTYPE。
  • 任意數量的評論和空格字符。
  • 根元素,以html元素的形式。
  • 任意數量的評論和空格字符。

來源:http://www.w3.org/TR/html5/syntax.html#writing

對於這個問題的目的,規範說的文件必須以DOCTYPE開始並且後面有根html元素。雖然meta標籤可能仍然有效,但今天並不保證它會這樣做,並且在將來繼續這樣做。

0

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> 
+1

請不要鏈接到w3schools,這是在StackOverflow廣泛不喜歡(見http://w3fools.com爲原因)。你可能已經鏈接到一個包含正確信息的頁面,但該網站有很多不正確的和誤導性的信息 - 並以任何方式鏈接到w3schools使其信譽**不**應得的。 (如果您使用Google搜索,並且擁有Google帳戶,則可以[輕鬆阻止結果](http://support.google.com/websearch/bin/answer.py?hl = en&answer = 1210386)來自w3schools) – freefaller

+0

感謝@freefaller – Denis

1

的meta標籤必須是<head></head>部分內。之前,不能添加任何東西<!DOCTYPE html>

Here is detailed description of DOCTYPE

+0

您可能想要選擇一個更好的鏈接......該文章已有8年曆史,圍繞FrontPage編寫,並在多個領域過時/錯誤。 –

0

你應該插入HTML頁面中的部分以下行,替換HTTP:實際example.com/網頁要重定向你的觀衆:

<元HTTP的當量= 「刷新」 內容= 「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>