For the HTML auto-redirect solution, we are going to make use of meta element with http-equiv and content attributes. The value for http-equiv will be refresh and as the name suggests, it will refresh the page in a specific time interval.
But refreshing the page is not our goal and that is why we are making use of the content attribute. We need to specify 2 things in this attribute, the number of seconds to wait before redirect and the URL to which we want to auto-redirect. You can provide here either relative URL or absolute URL.
The location object contains replace() method which will help us in redirecting to another page. The replace() methods take a URL as a parameter. Again, that URL can be relative or absolute.
In the following example, we will cover both the solutions mentioned above. We will simply display a counter of 5 seconds on the screen and as soon as it completes, the redirection to google.com will be triggered. Please have a look over the code example and the steps given below.
HTML & CSS
We have an h1 element in the HTML file. It contains style attribute to center align the text content.
HTML Auto Redirect
We have added a meta element with http-equiv and content attributes in the head element.
The value of http-equiv is set to refresh. It will help us in refreshing the page.
The value of the content attribute is set to "5; url=https://www.google.com/" and this means that wait for 5 seconds before refreshing the page and on refresh redirect to google.com