Simulate an HTTP Header
Description
The final use for the meta element is to override the value of one of the HTTP (Hypertext Transfer Protocol) headers.
HTTP is what you usually use to transport HTML data between the server and the browser.
Each HTTP response from the server contains a series of headers that describe the content,
and you can use the meta
element to simulate or replace three of those headers.
Example
The following code uses the meta
Element to Simulate an HTTP Header
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="refresh" content="5"/>
</head><!-- ww w .j av a 2 s .co m-->
<body>
<p>This is a test</p>
<a href="http://java2s.com">Visit java2s.com</a>
</body>
</html>
You use the http-equiv
attribute to specify which header you want to simulate,
and the content
attribute to provide the value you want to use.
In the code above, refresh
header is set to 5,
which has asked the browser to reload the page every five seconds.
Jump
If you follow the refresh interval with a semicolon and a URL, the browser will load the specified URL after the interval has passed.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="refresh" content="3; http://www.java2s.com"/>
</head><!-- ww w . java2 s . c om-->
<body>
<p>This is a test.</p>
<a href="http://java2s.com">java2s.com</a>
</body>
</html>
Note
There are three permitted values for the http-equiv
attribute listed in the following.
- Attribute Value:refresh
set a period, in seconds, after which the current page should reload from the server. You can also specify a different URL to be loaded. For example:<meta http-equiv="refresh" content="5; http://www.java2s.com"/>
- Attribute Value:default-style
set preferred stylesheet that should be used with this page. The value of the content attribute must match the title attribute on a script or link element in the same document. - Attribute Value:content-type
This is an alternative way of specifying the character encoding of the HTML page. For example:<meta http-equiv="content-type" content="text/html charset=UTF-8"/>