Last updated on February 26th, 2015 at 02:09 am

VN:F [1.9.22_1171]
Rating: 8.8/10 (5 votes cast)

This script can be used as a countdown timer before displaying a download link or any other hyperlink on your webpage. This is very basic script but you can make it more powerful by implementing, Get IP Address And Generate Time Limited Download Link Using PHP along with this.

This code is highly customizable and you can add dynamically the time duration and also the hyperlink which you need the webpage to display after x minutes or seconds.

The initial part of the script has couple of variables where you can set the time required for the download link to appear.
Here you are free to declare the minutes from 0 to 59 and seconds from 0 to 60.

var minutes =0;
var seconds=60;

Now the next part is declaring the URL and the Hyperlink name

url='http://mistonline.in';
LINK_NAME='Mistonline.in Website'

The variable URL can have the hyperlink that you need to add and the LINK_NAME variable will be the name of the hyperlink.

Please leave the rest of the script as it is and you are done.

Here is the complete script

<html><body><title>CountDown Before Link Appears</title>
<script type="text/javascript">
//Script from Mistonline.in, Please support our website and please dont delete this line
//declare variables
//Intial Minutes Count
var minutes =0;
//Intial Seconds Count
var seconds=40;
//URL Details
url='http://mistonline.in';
LINK_NAME='Mistonline.in Website'
//Please dont edit anything below if you are not sure what you are doing
var timer=setInterval(function(){myCounter()},1000);
function myCounter()
{

if(minutes > 59 || minutes < 0)
{
document.getElementById("time").innerHTML="<font color='red'>Please check the minutes variable, Set it in between 0 to 59</font>";
}else
{
     seconds--;
     if(seconds==0)
        {
          minutes=minutes-1;
          seconds=60;
        }
     document.getElementById("time").innerHTML=minutes +" Minutes "+seconds+" Seconds";
         if(minutes==-1)
             {
               clearTimeout(timer);
               document.getElementById("time").innerHTML="Your Download Link Has Been Generated";
			   document.getElementById("data").innerHTML="<a target='_blank' href='"+url+"'>"+link_name+"</a>";
			   
 }            }
}
</script>
<center><h2><div id="data">Please wait for the link to be generated.<p></div>
<div id="time"></div></h2>
</center></body></html>

Please find the demo below.
DEMO

VN:F [1.9.22_1171]
Rating: 8.8/10 (5 votes cast)
6 thoughts on “Countdown timer before displaying download link or hyperlink using javascript”
  1. Broo I Need your help how to use this code in post i added this code directly in post but it wont work then i added it with some html plugin then it works but when i change +url+ to my url it wont work again please help me i need your help

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    1. Hello Akshay,

      What is the error you are seeing? Please change the URL variable to lowercase url as shown below and then provide your own hyperlink.

      //URL Details
      url='http://mistonline.in';
      
      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
  2. hi,Thanks for this nice tutorials.
    I want to use “Countdown timer before displaying download link or hyperlink using javascript”, in my website.But it is not generating any link, it just outputs “time”element ,but not data element..I have not changed anything from your code.Please reply soon.
    Thanks.

    VA:F [1.9.22_1171]
    Rating: 2.0/5 (1 vote cast)
    1. Please check the demo webpage. Try using the below code. This should work.

      <script>var minutes =0;
      var seconds=40;
      url='http://mistonline.in';
      link_name='Mistonline.in Website'
      var timer=setInterval(function(){myCounter()},1000);
      function myCounter()
      {
      
      if(minutes > 59 || minutes < 0)
      {
      document.getElementById("time").innerHTML="<font color='red'>Please check the minutes variable, Set it in between 0 to 59</font>";
      }else
      {
           seconds--;
           if(seconds==0)
              {
                minutes=minutes-1;
                seconds=60;
              }
           document.getElementById("time").innerHTML=minutes +" Minutes "+seconds+" Seconds";
               if(minutes==-1)
                   {
                     clearTimeout(timer);
                     document.getElementById("time").innerHTML="Your Download Link Has Been Generated";
      			   document.getElementById("data").innerHTML="<a target='_blank' href='"+url+"'>"+link_name+"</a>";
       }            }
      }
      </script>
      <center><h2><div id="data">Please wait for the link to be generated.<p></div><div id="time"></div>
      
      VN:F [1.9.22_1171]
      Rating: 5.0/5 (1 vote cast)
  3. Is this possible that given link web page open automatically after the given time is over?
    Please reply soon.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × two =