HTML page redirection.

To redirect visitors from one page to another in HTML, you can use the HTML <meta> tag or the JavaScript window.location method.


  1. Using the HTML <meta> tag:

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="refresh" content="0; URL='http://example.com/page2.html'" />

</head>

<body>

<p>You will be redirected to page 2 in a moment...</p>

</body>

</html>


Explanation: In the example above, the http-equiv attribute of the <meta> tag specifies the type of HTTP header that will be returned from the server. The content attribute specifies the number of seconds before the page should be refreshed, followed by the URL to redirect to.


2. Using the JavaScript window.location method:

<!DOCTYPE html>

<html>

<head>

<script>

      window.location.href = "http://example.com/page2.html";

</script>

</head>

<body>

<p>You will be redirected to page 2 in a moment...</p>

</body>

</html>


Explanation: In the example above, the window.location.href property is used to specify the URL to redirect to.

Note: Note that in both cases, it is a good practice to provide a message to the user explaining that they will be redirected to another page. This can be done using a simple <p> tag or any other HTML element.

Post a Comment

Previous Post Next Post
© 2023 Developed and Design By
NILESH NISHAD