HTML DOM Meta httpEquiv 屬性

2018-08-04 20:40 更新

Meta httpEquiv 屬性

Meta 對(duì)象參考手冊(cè) Meta 對(duì)象

定義和用法

httpEquiv 屬性可設(shè)置或者返回 content 屬性中HTTP 頭部信息。

http-equiv 屬性可以使用偽裝 HTTP 響應(yīng)頭部信息。

http-equiv 屬性值依賴 content屬性的值。

注意:如果 name 屬性已設(shè)置, http-equiv 屬性就無(wú)需設(shè)置。

語(yǔ)法

設(shè)置 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

實(shí)例:

<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).

實(shí)例:

<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.

實(shí)例:

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

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

實(shí)例:

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

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

實(shí)例:

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

last-modified Specifies the last modification date.

實(shí)例:

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

location Redirects the visitor to another location.

實(shí)例:

<meta http-equiv="location" content="URL=http://o2fo.com">

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

實(shí)例:

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

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

實(shí)例:

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

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


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 httpEquiv 屬性


實(shí)例

實(shí)例

顯示 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 對(duì)象參考手冊(cè) Meta 對(duì)象
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)