第1章 第892节 dom meta httpEquiv

推荐给朋友

Meta httpEquiv 属性

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

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

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

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

语法

设置 httpEquiv 属性:

linkObject.httpEquiv="HTTP-header"

返回 httpEquiv 属性:

linkObject.httpEquiv

一些常用的 HTTP-header 值:

描述
cache-control 控制文档的缓存机制。
允许的值:
public - 所有内容都将被缓存(客户端和代理服务器都可缓存)
private - 内容只缓存到私有缓存中(仅客户端可以缓存,代理服务器不可缓存)
no-cache - 不缓存
no-store - 缓存当不归档 but not archived
实例:
<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.nowcoder.com">
refresh 定义间隔多久后刷新页面。
实例:
<meta http-equiv="refresh" content="300">
set-cookie 创建一个 cookie ,包含了 cookie 名,cookie 值,过期时间。
实例:
<meta http-equiv="set-cookie" content="nowcodercookie=myContent;expires=Fri, 30 Dec 2015 12:00:00 GMT; path=http://www.nowcoder.com">
window-target 指定要载入的框架名

浏览器支持

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

在线实例

实例

显示 HTTP 头部信息:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>牛客教程(nowcoder.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>

尝试一下