how to do this in javascript

Discussion in 'JavaScript' started by viron86, Feb 21, 2009.

  1. #1
    i want something like timer that we see in rapidshare free usage that makes user to wait for sometime before the download link appears
    please give me some code eg
     
    viron86, Feb 21, 2009 IP
  2. rsrikanth05

    rsrikanth05 Well-Known Member

    Messages:
    1,362
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    190
    #2
    You'll need something like PHP, or ASP for that, I haven't managed to do it with JavaScript.
     
    rsrikanth05, Feb 21, 2009 IP
  3. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    With javascript, just have a div containing the time left before the download link becomes available. Then, every second minus one from an integer, and put it into the innerHTML of the div. Also, check if the integer is 0, and if it is, then change the innerHTML to the link.
    Have I understood you correctly? Need help coding that?
     
    thefluffball, Feb 21, 2009 IP
  4. rsrikanth05

    rsrikanth05 Well-Known Member

    Messages:
    1,362
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    190
    #4
    I would like it if you did that.
    I'm a bit rusty with Javascript.
     
    rsrikanth05, Feb 22, 2009 IP
  5. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here you go. Enjoy. :) I added some CSS to make it look pretty. :p

    <div id="container" style="width:125;height:23;background:#DDDDDD;text-align:center;padding:3px;">
    <form name="form"><input type="text" size="8" name="time"></form></div>
    
    <script><!-- //
    var countdownfrom = 10;
    secondsleft = countdownfrom+1;
    document.form.time.value = countdownfrom;
    function countdown(){
    	if (secondsleft > 0){
    		secondsleft -= 1;
    	} else {
    		document.getElementById('container').innerHTML = '<a href="downloadme.zip" alt="Download Me!">Click to download</a>';
    	}
    	document.form.time.value = secondsleft;
    	setTimeout("countdown()",1000);
    }
    countdown();
    --></script>
    Code (markup):
    This is free for anyone to use, and although some form of credits are not needed, they are appreciated. ;)

    It should be self-explanatory, but if you need any further help - Just ask.
     
    thefluffball, Feb 22, 2009 IP
    rsrikanth05 likes this.
  6. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hey, :).. this is how you could do it, but obviously this is not a secure method, since the link is stored in the code itself, if you could get the link through ajax out of a php page, there you could incorporate a timer [ so that the user doesn't play with the javascript to get past the timer and get the link through it as well..

    <html>
    <head>
    </head>
    <body>
    <div id="timerDiv">
    </div>
    
    <script language="javascript">
    var start = 10;
    timerChange();
    function timerChange(){
    	document.getElementById("timerDiv").innerHTML = start;
    	start--;
    	if (start >= 0){
    		setTimeout(timerChange, 1000);
    	}else{
    		document.getElementById("timerDiv").innerHTML = "LINK";
    	}
    }
    
    </script>
    </body>
    </html>
    HTML:
     
    hackfanatic, Feb 22, 2009 IP
    rsrikanth05 likes this.
  7. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You just did exactly the same as me. :eek: Oh well.

    Edit: By the way, if you would like, I could add milisecond support to it.
     
    thefluffball, Feb 22, 2009 IP
  8. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    lol, sorry.. i clicked the reply button and then wrote the code.. i guess you must have replied in that while..

    Cheers.. :)
     
    hackfanatic, Feb 22, 2009 IP
  9. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ok, fair enough. :p Nothing major either way.
     
    thefluffball, Feb 22, 2009 IP
  10. viron86

    viron86 Active Member

    Messages:
    426
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #10
    thank for the i wll try it
     
    viron86, Feb 22, 2009 IP
  11. rsrikanth05

    rsrikanth05 Well-Known Member

    Messages:
    1,362
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    190
    #11
    Thanks a lot, both of you.
    I've repped both of you..
     
    rsrikanth05, Feb 22, 2009 IP
  12. thefluffball

    thefluffball Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    No problem, thanks for that. :)
     
    thefluffball, Feb 22, 2009 IP
  13. rsrikanth05

    rsrikanth05 Well-Known Member

    Messages:
    1,362
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    190
    #13
    You're most welcome...
    :D
     
    rsrikanth05, Feb 23, 2009 IP