How to redirect one HTML page to another on load
How can you automatically redirect one HTML page to another when it loads?
What are the different methods to redirect users from one HTML page to another on page load? Learn how to use HTML meta tags or JavaScript to set up seamless page redirection.
To redirect one HTML page to another when it loads, you can use either an HTML <meta</span>> tag or JavaScript. Both methods are simple and effective, depending on your needs.
1. Using HTML <meta</span>> tag:
This method works without JavaScript and is placed in the
section of your HTML.
- content="5" means the current page will wait 5 seconds before redirecting.
- Change the URL to wherever you want to redirect.
- This is great for basic redirection without scripting.
2. Using [removed]
If you need more control (e.g., based on user action or condition), JavaScript is the way to go.
[removed] = function() {
[removed].href = "https://example.com";
}
- This method triggers the redirect as soon as the page loads.
- It’s more dynamic and can be combined with logic if needed.
Key Points:
- Use meta refresh for simple timed redirects.
- Use JavaScript for flexibility and interactivity.
- Avoid overusing redirects, as they can impact user experience and SEO.
- Choose the method that suits your project needs. For most static pages, the meta tag works fine; for more control, go with JavaScript.