例
返回的HTTP标头在信息content属性:
var x = document.getElementsByTagName("META")[0].httpEquiv;
x的结果将是:
content-type
试一试» 定义和用法
该httpEquiv属性设置或返回在信息的HTTP标头content属性。
在http-equiv属性可以用来模拟一个HTTP响应头。
该值http-equiv属性依赖于价值content属性。
注意:如果name属性设置,在http-equiv属性不应设置。
浏览器支持
该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";
试一试» 元对象