最新的Web開發教程
 

元httpEquiv物業

元對象參考 元對象

返回的HTTP標頭在信息content屬性:

var x = document.getElementsByTagName("META")[0].httpEquiv;

x的結果將是:

content-type
試一試»

定義和用法

該httpEquiv屬性設置或返回在信息的HTTP標頭content屬性。

http-equiv屬性可以用來模擬一個HTTP響應頭。

該值http-equiv屬性依賴於價值content屬性。

注意:如果name屬性設置,在http-equiv屬性不應設置。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

該httpEquiv屬性在所有主流瀏覽器的支持。


句法

返回httpEquiv屬性:

metaObject .httpEquiv

設置httpEquiv屬性:

metaObject .httpEquiv=HTTP-header

一些常用的HTTP標頭值是:

Value Description
content-type Specifies the character set for the contents of the document.

Tip:It is recommended to always specify the character set.

Example:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

default-style Specifies the preferred style sheet to use.

Example:

<meta http-equiv="default-style" content=" the documents preferred stylesheet ">

Note: The value of the content attribute above must match the value of the ttitle attribute on a link element in the same document, or it must match the value of the title attribute on a style element in the same document.

refresh Defines a time interval for the document to refresh itself.

Example:

<meta http-equiv="refresh" content="300">

Note: The value "refresh" should be used carefully, as it takes the control of a page away from the user. Using "refresh" will cause a failure in W3C's Web Content Accessibility Guidelines .

返回值

Type Description
String Information about the HTTP response message header

更多示例

更改HTTP-當量和內容屬性的值。 下面的例子將刷新文檔每30秒:

document.getElementsByTagName("META")[0].httpEquiv = "refresh";
document.getElementsByTagName("META")[0].content = "30";
試一試»

元對象參考 元對象