1

i have a small issue, i want to redirect page on click using jquery here is my code

$('#submit').click(function(){
   window.location.href='index.php';
}) 

Now is there any way to delay redirect for 5 second.. i mean when click on button user wait at least 5 second on same page and then redirect to index.php i also tried this but it's not working

$('#submit').click(function(){
       window.location.href='index.php';
    } 5000)
Joe
  • 51
  • 2
  • 11

3 Answers3

1

Try this:

$('#submit').click(function()
{
    setTimeout(function(){ window.location.href='index.php'; }, 5000);       
});
Andy-Delosdos
  • 3,560
  • 1
  • 12
  • 25
0

Use setTimeout function.

$('#submit').click(function(){
  setTimeout(function(){
       window.location.href='index.php';
  },5000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" id="submit">Submit</button>
jonju
  • 2,711
  • 1
  • 13
  • 19
0
$('#submit').click(function(){
    var delay = 1000; //Your delay in milliseconds
    setTimeout(function(){ window.location = URL; }, delay);
});
Michael Parker
  • 12,724
  • 5
  • 37
  • 58
Ghayyour Ahmed Butt
  • 383
  • 1
  • 2
  • 12