Practical Web Programming

Saturday, January 24, 2009

How to Redirect a Web Page Using HTML

How to redirect a web page using HTML is just easy as redirect in PHP. While in PHP we use the header function, in HTML, we use the meta tag to accomplish the same task.

Here's an example.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HTML Redirect in Meta Tag</title>
<meta http-equiv="REFRESH" content="0;url=http://localhost/redirect.php">
</head>

<body>

</body>
</html>


In HTML redirection, the content attribute of the meta tag should contain the number of seconds to pause before doing the redirection and the page where to redirect. The above sourcecode will redirect the current page to http://localhost/redirect.php in 0 second.

If you want to notify your visitor before redirecting, you can specify the number of seconds to pause. This way, you can display a message in your current page.

Here's how.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>HTML Redirect in Meta Tag</title>
<meta http-equiv="REFRESH" content="5;url=http://localhost/redirect.php">
</head>

<body>

<p>This page will redirect in 5 seconds...</p>

</body>
</html>

0 comments:

Recent Post