2011-02-02 43 views
3

我只是檢查是否有效,將元素放置在<noscript>元素內作爲回退以顯示動態內容。它驗證罰款與HTML 5的文檔類型,但是對於HTML 4.01,我得到以下錯誤:爲什麼不會<iframe>元素在HTML 4.01中驗證?

Line 9, Column 35: element "IFRAME" undefined
<iframe name="test" src="test.htm"></iframe>

You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:

  • incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "" element),
  • by using vendor proprietary extensions such as "" or "" (this is usually fixed by using CSS to achieve the desired effect instead).
  • by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case).

這是我削成HTML到:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" 
      "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
    <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
</head> 
<body> 
    <div> 
    <iframe name="test" src="test.htm"></iframe> 
    </div> 
</body> 
</html> 

的元素定義以下網址的HTML 4.01規範:http://www.w3.org/TR/html401/present/frames.html#h-16.5

它通過一個過渡文檔類型,所以我想我的問題是「爲什麼它不允許嚴格的文檔類型,即使它在規範中定義?」。

+4

可能在嚴格的DTD中無效。你可以轉移到Transitional嗎? – Craig 2011-02-02 10:55:20

+0

@Craig:根據W3Schools,沒關係,但那也是我第一次嘗試。 – Mikaveli 2011-02-02 11:00:57

回答

5

"Why is it disallowed in a strict doctype, even though it's defined in the specification?

很多東西都在規範中定義,但嚴格禁止。 <font>想起來。這些是規範開發人員需要記錄的事情,當天在瀏覽器中使用,但應該從瀏覽器中轉移出去。

我能想到的兩個原因,他們可能會認爲:

3

iframe中不包含在HTML嚴格來實現。對於驗證,請嘗試使用對象元素。

<object data="test.html" type="text/html"></object> 

您還應該將寬度和高度屬性添加到對象元素。請注意,與iframe對象不能成爲任何頁面鏈接的目標不同。

除非由於某些原因您特別需要html4嚴格驗證,否則最好使用html5文檔類型。

相關問題