devxlogo

Redirecting to Another URL with setTimeout

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).

See also  5 Tips for Choosing the Right Medical Software for Your Practice
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist