codecamp

HTML DOM Meta httpEquiv 属性

Meta httpEquiv 属性

Meta 对象参考手册 Meta 对象

定义和用法

httpEquiv 属性可设置或者返回 content 属性中HTTP 头部信息。

http-equiv 属性可以使用伪装 HTTP 响应头部信息。

http-equiv 属性值依赖 content属性的值。

注意:如果 name 属性已设置, http-equiv 属性就无需设置。

语法

设置 httpEquiv 属性:

linkObject.httpEquiv="HTTP-header"

返回 httpEquiv 属性:

linkObject.httpEquiv

一些常用的 HTTP-header 值:

描述
cache-control Controls the caching mechanism to use for the document.

Available values:

  • public - cached in public shared caches
  • private - cached in private cache
  • no-cache - not cached
  • no-store - cached but not archived

实例:

<meta http-equiv="cache-control" content="no-cache">

content-language Specifies the natural language(s) of the document (used by search engines to categorize pages by language).

实例:

<meta http-equiv="content-language" content="en-US">

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

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

实例:

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

date Specifies the date and time when the page was created.

实例:

<meta http-equiv="date" content="Wed, 16 Feb 2011 22:34:13 GMT">

expires Specifies the date and time when the page will expire.

实例:

<meta http-equiv="expires" content="Fri, 30 Dec 2011 12:00:00 GMT">

last-modified Specifies the last modification date.

实例:

<meta http-equiv="last-modified" content="Mon, 03 Jan 2011 17:45:57 GMT">

location Redirects the visitor to another location.

实例:

<meta http-equiv="location" content="URL=http://www.w3cschool.cn">

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

实例:

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

set-cookie Creates a cookie with specified name,expires date and value.

实例:

<meta http-equiv="set-cookie" content="w3scookie=myContent;expires=Fri, 30 Dec 2011 12:00:00 GMT; path=http://www.w3cschool.cn">

window-target Specifies the name of the frame where the current document must be loaded


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 httpEquiv 属性


实例

实例

显示 HTTP 头部信息:

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

<script>
function displayResult()
{
var x=document.getElementsByTagName("meta")[0].httpEquiv;
alert(x);
}
</script>

</head>
<body>

<button type="button" onclick="displayResult()">Display HTTP-Equiv</button>

</body>
</html>

尝试一下 »


Meta 对象参考手册 Meta 对象
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

HTML DOM对象

HTML DOM 引用对象

HTML DOM Password 对象

HTML DOM Link 对象

HTML DOM Select 对象

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }