Redirect To Another Page After 5 Seconds?


we will learn redirect in javascript, If you are looking for how to redirect to another page in jquery after 5 seconds then I will give you a simple example to redirect to URL after 2 seconds, 3 seconds, 5 seconds, or any specific time in jquery. we will use setTimeout() for redirect to URL after 5 seconds in jquery.

In this example, we will create one button to redirect another page after 2 seconds. when you click on the button, then the button will say to you "Redirecting soon....". After 5 seconds it will redirect to the given URL page.

Redirect To Another Page After 5 Seconds? - Step By Step

You can see bellow a full example will help to redirect to another page URL in jquery.

Example 1:
<!DOCTYPE html>
<html>
<head>
    <title>Redirect to Another Page After 5 Seconds - Php Coding Stuff</title>
    <script src="https://code.jquery.com/jquery-3.5.1.js" crossorigin="anonymous"></script>
</head>
<body> 
   
<button>Click to redirect</button>
     
<script type="text/javascript">
    
    $("button").click(function(){
        $(this).text('Redirecting After 2 Seconds................');
    
        var delay = 2000; 
        var url = 'https://www.phpcodingstuff.com/'
        setTimeout(function(){ window.location = url; }, delay);
    })
    
</script>
   
</body>
</html>

I hope it can help you...

Leave a Reply

Your privacy will not be published. Required fields are marked *

We'll share your Website Only Trusted.!!

close