Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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.

 
<META HTTP-EQUIV="REFRESH" CONTENT="5;URL='newpage.html'"> 

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.

 

 

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