To perform a HTML redirect we need to make use of the meta refresh tag. This is a particular meta tag which is used to tell the browser to go to another location. Redirecting a browser using the meta refresh method is discouraged since an unexpected redirection may disorient users.
In some cases, redirecting a web page using the meta refresh is required. The method is suitable for periodically refreshing a dynamic page to get new news or status updates for example, and is used when Javascript methods of redirection are unwanted.
To redirect to http://www.example.com/ after 2 seconds, we would place the following in the HEAD section of the markup:
<meta http-equiv="refresh" content="2;url=http://www.example.com/" />Of course, we can change the number 2 to other numbers for longer of shorter delays as required. Setting the number to 0 will perform the redirect immediately as in the code below.
<meta http-equiv="refresh" content="0;url=http://www.example.com/" />As a side issue, if we want to refresh the current page we can do it like this:
<meta http-equiv="refresh" content="5" />We insert the tag as usual, but this time we only specify a time and leave out the URL part altogether. Refreshing the current page is useful for updating dynamic pages.
A user may not want to be redirected to an entirely different web page so this may cause dissatisfaction if that is what it is used for.
Redirecting to another web page using a very short interval may cause the user to be stuck on the new page since when the user hits the 'Back' button in their browser, they might land on the original page and get redirected (quite quickly) once again.