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
广告