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 Add Google Charts on a Webpage?
- Reader's View of a GeeksforGeeks webpage
- How To Add Google Translate Button On Your Webpage?
- Reading selected webpage content using Python Web Scraping
- How to connect multiple MySQL databases on a single webpage ?
- HTML Course | Structure of an HTML Document
- HTML Course | Basics of HTML
- HTML | DOM HTML Object
- HTML | th Tag
- HTML | col Tag
- HTML | <nav> Tag
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.