Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Redirect to URL after specified time

Is there a way to use JQuery to redirect to a specific URL after a give time period?

like image 964
Brian Avatar asked Sep 01 '11 21:09

Brian


People also ask

How do I automatically redirect a page after 5 seconds?

To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.

How do I redirect a button to another page?

By using HTML Anchor Tags <a>.. </a>, you can Redirect on a SIngle Button Click [html button click redirect]. To use HTML Anchor tags to redirect your User to Another page, you need to write your HTML Button between these HTML Anchor Tag's starting <a> and Closing </a> Tags.


2 Answers

You could use the setTimeout() function:

// Your delay in milliseconds var delay = 1000;  setTimeout(function(){ window.location = URL; }, delay); 
like image 153
Rion Williams Avatar answered Sep 23 '22 01:09

Rion Williams


You don't really need jQuery for this. You could do it with plain javascript using the setTimeout method:

// redirect to google after 5 seconds window.setTimeout(function() {     window.location.href = 'http://www.google.com'; }, 5000); 
like image 39
Darin Dimitrov Avatar answered Sep 24 '22 01:09

Darin Dimitrov