HTML - http-equiv 屬性



HTML 的 **http-equiv** 屬性用於指定文件元資料的 HTTP 頭,通常用於控制瀏覽器或伺服器的行為。此屬性命名為 http-equiv,因為所有允許的值都是特定 HTTP 頭的名稱。

如果 http-equiv 屬性的值設定為 refresh,並且 content 屬性接受任何網站或頁面的時間間隔和 URL,則它將在時間間隔後重新整理頁面並將其重定向到給定的 URL。refresh 指令指定頁面應重新載入之前的秒數,僅當 content 屬性包含非負值時。

語法

<meta http-equiv = "value"></meta>

以下是 http-equiv 支援的值列表:

  • content-security-policy
  • content-type
  • default-style
  • x-ua-compatible
  • refresh

應用於

以下列出的元素允許使用 HTML http-equiv 屬性:

元素 描述
<meta> HTML <meta> 標籤用於向網頁新增元資料。

HTML http-equiv 屬性示例

以下示例將說明 HTML http-equiv 屬性的用法,以及我們應該在哪裡以及如何使用此屬性!

使用 'http-equiv' 屬性重新整理網頁

在以下示例中,HTML 'http-equiv' 屬性用於 <meta> 元素中定義一個 pragma 指令。我們將字串“refresh”指定為此屬性的值,該值定義頁面應根據時間間隔重新整理。

<!DOCTYPE html>
<html lang="en">

<head>
   <!--http-equiv attribute-->
   <meta http-equiv="refresh" content="10">
   <title>HTML 'http-equiv' attribute</title>
</head>

<body>
   <h3>
      Example of the HTML 'http-equiv' attribute
   </h3>
   <p>
      The page should be refreshed automatically 
      with respect to the time interval.
   </p>
</body>

</html>

在特定時間後重定向網頁

考慮另一種情況,我們將使用 <meta> 標籤中的“http-equiv”屬性在特定時間間隔後將當前網頁重定向到另一個頁面。

<!DOCTYPE html>
<html lang="en">
<head>
   <!-- HTML http-equiv Attribute-->
   <meta 
      http-equiv="refresh" 
      content="5;url=/html/html_overview.htm" >
   <title>HTML 'http-equiv' attribute</title>
</head>
<body>
   <h3>HTML 'http-equiv' Attribute</h3>
   <p>
      The page will redirect to the HTML Introduction 
      website after 5 seconds.
   </p>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
http-equiv
html_attributes_reference.htm
廣告
© . All rights reserved.