Want To Be A Blogger  →  Start A Blog  →  Increase Traffic  →  Make Money Online  →  Recommended Things

Redirect Webpage After Delay Using JavaScript

Friday, Dec 15, 2017

Tags:- JavaScript HTML


In this tutorial we will show you how to redirect webpage to another after some delay using JavaScript because sometimes there are situations when you have to redirect user to another page after some time so this kind of method will help to solve that problem.You may also like detect and redirect to mobile site using PHP.


See Demo
Redirect Webpage After Delay Using JavaScript


To Redirect Webpage After Delay It Takes Only One Step:-

  1. Make a HTML file and define markup and scripting


Step 1.Make a HTML file and define markup and scripting

We make a HTML file and save it with a name redirect.html

<html>
<head>
<script type="text/javascript">
function redirect()
{
 var count = 10;
 setInterval(function()
 {
  document.getElementById('countdown').innerHTML = "Redirect In "+count+" Seconds...";
  if (count == 0) 
  {
   window.location = ''; 
  }
  count--;
 },1000);
}
</script>
</head>
<body>
<div id="wrapper">
<div id="redirect_div">
 <input type="button" value="Click To Redirect" onclick="redirect();">
 <p id="countdown"></p>
</div>
</div>
</body>
</html>

In this step we create a button to call redirect() function and in redirect() function we create a 'count' variable and set the value 10, here 10 represents the sec it takes to redirect to another page and then create if() condition to check if count=0 redirect to same page we use blank in window.location you can use any page to redirect and then we decrement the count to -1 and when the count reaches to 0 it redirect the user to another page.You may also like print webpage using javascript.



Thats all, this is how to redirect webpage after delay using JavaScript.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Subscribe Our Newsletter And Get Tutorials And Offers Via Email

About Me


Hello, My Name is Mudit Jain. I am a Web Developer, Professional Blogger and Digital Marketer from India. I am the founder of TalkersCode. I started this blog in february 2015 to help web developers & bloggers by providing easy and best tutorials, articles and offers for web developers and bloggers.