• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
I want to redirect page after some time in javascript, lets say i want to redirect after specific time ie 5 seconds or redirect after 2 seconds, how do i do this? If someone can show me to do redirect after 5 seconds with coundown that would be good too?
by (930 points)  

2 Answers

0 votes

Some times there is need to redirect users to another page after specific time ie 3 secs or 5 seconds, there are number of methods to achieve this.

In following code we have button to redirect after 5 seconds, you can change timings as per your requirement

Javascript Code for redirects after 5 Seconds


<div id="redirect5SecMsg"></div>

<input type="button" onclick="redirect5Sec()" value="Click to Redirect"/>


function redirect5Sec(){

    document.getElementById('redirect5SecMsg').innerHTML = 'Redirecting after <span id="countNumbers">5</span> seconds....';

    var count = 5;



        document.getElementById('countNumbers').innerHTML = i;

        if (i== 0) {

            window.location = 'https://www.kodlogs.com'; 





by (930 points)  
0 votes
There is another way to redirect user to another pager after certain delay:

Use setTimeout to achieve this kind of delay

$(function redirectafterdelay() {

  setTimeout(function() {


  }, 5000);


Or you can use

setTimeout(function(){ window.location = "http://www.kodlogs.com"; },5000);
by (930 points)