1. 首先介绍一下HTML中的特殊属性<META ...> - HTTP-EQUIV
下面一段文字引用自http://www.htmlcodetutorial.com/document/_META_HTTP-EQUIV.html.
HTTP-EQUIV tells the browser to pretend that an additional HTTP header was sent. The name of the header is the value of the HTTP-EQUIV attribute and the value of the header is the value of the CONTENT attribute.
Was that confusing? Ok, let's start from the beginning. Whenever a web server sends a web page it also sends an additional set of information about the page called headers. The browser doesn't display these headers, it uses them internally to understand how to display the page. Here's an example of some page headers:
HTTP/1.1 200 OK
Date: Sun, 12 Aug 2001 15:54:22 GMT
Server: Apache/1.3.14 (Unix) ApacheJServ/1.1.2 Mod_dtcl 0.6.4 PHP/3.0.18
Last-Modified: Fri, 22 Jun 2001 00:28:46 GMT
ETag: "75f87-200-3b32913e"
Accept-Ranges: bytes
Content-Length: 512
Connection: close
Content-Type: text/html
The purpose of HTTP-EQUIV is to tell the browser to pretend that an additional header was sent. So, for example, if we wanted to tell the browser to act as if a header like this were sent:
Refresh: 5
we would use a tag like this:
<META HTTP-EQUIV="Refresh" CONTENT="5">
The contents of HTTP-EQUIV are case-insensitive. The most common use for HTTP-EQUIV is for redirecting.
2. 接下来介绍一下如何应用<META ...> - HTTP-EQUIV实现站点重定向
You can use <META ...> to tell the web browser to automatically move to another web page, or refresh the current page, after a specified period of time.
To have the page automatically refresh itself every x seconds, use a tag like this:
<META HTTP-EQUIV="REFRESH" CONTENT=&quto;5%quto;>
This tells the browser to refresh the page (HTTP-EQUIV="REFRESH"), and that it should do so every five seconds (CONTENT="5").
Suppose, however, that you want the page to refresh itself by going automatically to another page. This is common, for example, when someone has moved their home page to a new location, but want someone who goes to the old location to still find a pointer. You could put this <META ...> tag in the page at the old location:
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=autoforward_target.html">
In this case the <META ...> tag works is like the first refresh example, only with a little added information. The first part is the same: CONTENT="5; URL=autoforward_target.html" tells the browser that the page should be refreshed. CONTENT="5; URL=autoforward_target.html" gives two pieces of information: that the page should refresh after five seconds, and that the new URL should be autoforward_target.html .
In a situation like this, you should also provide a regular link to the new page.
You can also use <META ...> tags to ensure that the browser does not cache the HTML document. Caching is the process of saving the HTML document locally, on the computer's hard drive, for future use so the browser doesn't have to download the document again. To ensure that the browser does not cache a particular page use the following code:
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
HTML的META标签还有很多很有意思的功能。想了解更多HTML标签及其属性,可以参考下面两个网站:
The global structure of an HTML document
HTML Quick List
没有评论:
发表评论