Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Intermediate
Jul 12, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Redirecting to Another URL with setTimeout

Most of Web developers may be familiar with the META REFRESH tag in HTML. This tag is used to take the user to another location automatically, after a specified delay. In the example given below, the browser automatically navigates to 'newpage.html', 5 seconds after the page is loaded.


In some cases, however, you might want to take the user to another page, perhaps depending on some actions and a varying time delay. In this context the META REFRESH tag cannot be used because it is dependent on the time when the page was loaded. The following JavaScript code snippet helps to achieve this feature using the setTimeout function.

setTimeout('window.location.href="newpage.html"', 10000); 
This statement, when called during the specific event or action, navigates the user automatically to "newpage.html" after a delay of 10 secs (10000 milliseconds).

Ajith Prasad
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date