Download Wait Timer

Discussion in 'JavaScript' started by Junije, Jul 19, 2009.

  1. #1
    Hi.

    I'm creating a website from which users will be able to download software, but in order to download it, they will have to wait for a certain time, like 5 minutes or so, for the download to start.
    So, when the timer would reach zero, the download would start, or a button would which would contain the link to download the file would appear.

    I would like to make this with JavaScript, since I don't know any other way I could do it. But I'm also a total n00b with JS, and can't do anything myself ^^

    Everything would look like that RapidShare download wait time, when you have to wait to download a file if you're a free user.

    So umm, can someone lead me in the right direction on how to do this? =D
     
    Junije, Jul 19, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    right. the idea in pseudo code is:

    1. produce your normal download link but set display to none in css in a layer with some id
    2. produce the message with a countdown element like <span id="timeleft">45</span>
    3. create a timer function in javascript - countdown, that updates the timeleft innerhtml every 1000ms. this is done via setTimeout or setInterval.
    4. when a certain condition has been met, i.e. your time left is 0 or times run is 0 if you do count-- - change the download link's display status to block

    things to note:
    reference the setInterval to a pointer that you can clear.

    eg. barebones js goes like so:

    var seconds = 45, countdown = function() {
        seconds--;
        document.getElementById("timeleft").innerHTML = seconds;
        if (seconds <= 0) {
            clearInterval(timesRun);
            document.getElementById("link").style.display = "block";
        }
    }, timesRun = setInterval(countdown, 1000);
    
    PHP:
    note: you need to make sure you have the html to match and also, as you get popular, people will figure this out and make greasemonkey scripts that just make the countdown to 0 instantly or just show the download link straight away. the best way for doing this is to also time it serverside and populate the download link through an ajax or jsonp update.

    good luck, i hope this helps you enough.
     
    dimitar christoff, Jul 19, 2009 IP
  3. Junije

    Junije Well-Known Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Thanks for the help, cleared things up a bit ^^

    So, people could bypass the countdown timer If they know how, that's not good. :\

    Maybe I'd be interested in the other option, serverside timer. Can I make this with PHP any MySQL?
     
    Junije, Jul 19, 2009 IP
  4. Junije

    Junije Well-Known Member

    Messages:
    136
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    No need to anwer =D Just got myself a server side PHP solution...
     
    Junije, Jul 20, 2009 IP
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    excellent. post the solution if you remember :)
     
    dimitar christoff, Jul 22, 2009 IP