It is often required to redirect to another webpage on loading a webpage, for example, due to the contents being moved to the new webpage.
Demonstrated here are two simple methods to redirect to another webpage on load.
Method-1: Using http-equiv attribute of the meta tag in HTML.
<meta http-equiv="refresh" content="seconds; url=URL">
After 2 seconds:
Note: In some older browsers, like Internet Explorer 6, refresh may cause unexpected results and impair the browser’s Back button. This is compensated for in most modern browsers (Internet Explorer 7 and higher, Google Chrome, Mozilla Firefox, Microsoft Edge).
window.location.href = "URL"
- How to use Meta Tag to redirect an HTML page?
- How to redirect a page to another page in HTML ?
- ES6 | Page Redirect
- Post/Redirect/Get (PRG) Design Pattern
- How to Add Google Charts on a Webpage?
- How to Add Apple's new San Francisco font on a Webpage using CSS ?
- How to click a button on webpage using selenium ?
- How To Add Google Translate Button On Your Webpage?
- Reader's View of a GeeksforGeeks webpage
- How to get title of a webpage using Selenium in Python?
- How to connect multiple MySQL databases on a single webpage ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.