Jquery redirect to url after specified time

Is there a way to use jQuery to redirect to a specific url after a given period of time?

+45
jquery redirect
Sep 01 2018-11-21T00:
source share
6 answers

You can use the setTimeout() function:

 // Your delay in milliseconds var delay = 1000; setTimeout(function(){ window.location = URL; }, delay); 
+88
Sep 01 '11 at 21:20
source share

You do not need jQuery for this. You can do this with simple javascript using the setTimeout method :

 // redirect to google after 5 seconds window.setTimeout(function() { window.location.href = 'http://www.google.com'; }, 5000); 
+45
Sep 01 2018-11-21T00:
source share
 $(document).ready(function() { window.setInterval(function() { var timeLeft = $("#timeLeft").html(); if(eval(timeLeft) == 0){ window.location= ("http://www.technicalkeeda.com"); }else{ $("#timeLeft").html(eval(timeLeft)- eval(1)); } }, 1000); }); 
+12
Apr 01 '13 at 3:28
source share

you can use

  $(document).ready(function(){ setTimeout(function() { window.location.href = "http://test.example.com/;" }, 5000); }); 
+6
Jan 24
source share

just use:

 setTimeout("window.location.href='yoururl';",4000); 

.. where "4000" is m.second

+4
May 28 '13 at 18:53
source share

I did a simple demo that revises in X for a few seconds and redirects the url job. If you do not want to wait for the count to finish, just click on the counter to redirect it without any time. A simple caunter that will count down during a ripple in the middle of the page. You can launch it onclick or while some page is loaded.

LIVE DEMO ONLOAD

LIVE DEMO ONCLICK

I also made a github repo for this: https://github.com/GlupiJas/redirect-counter-plugin

Sample JS code:

 // FUNCTION CODE function gjCountAndRedirect(secounds, url) { $('#gj-counter-num').text(secounds); $('#gj-counter-box').show(); var interval = setInterval(function() { secounds = secounds - 1; $('#gj-counter-num').text(secounds); if(secounds == 0) { clearInterval(interval); window.location = url; $('#gj-counter-box').hide(); } }, 1000); $('#gj-counter-box').click(function() //comment it out -if you dont want to allo count skipping { clearInterval(interval); window.location = url; }); } // USE EXAMPLE $(document).ready(function() { //var var gjCountAndRedirectStatus = false; //prevent from seting multiple Interval //call $('h1').click(function(){ if(gjCountAndRedirectStatus == false) { gjCountAndRedirect(10, document.URL); gjCountAndRedirectStatus = true; } }); }); 
+1
Jan 04 '16 at 4:19
source share



All Articles