Wordpress Themes - Credit Card - Debt Consolidation - Electronics - Debt Consolidation

PDA

View Full Version : how to do this in javascript


viron86
Feb 21st 2009, 7:04 am
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

rsrikanth05
Feb 21st 2009, 7:32 am
You'll need something like PHP, or ASP for that, I haven't managed to do it with JavaScript.

thefluffball
Feb 21st 2009, 7:42 am
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?

rsrikanth05
Feb 22nd 2009, 2:24 am
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?

I would like it if you did that.
I'm a bit rusty with Javascript.

thefluffball
Feb 22nd 2009, 3:23 am
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>

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.

hackfanatic
Feb 22nd 2009, 3:25 am
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>

thefluffball
Feb 22nd 2009, 3:39 am
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.

hackfanatic
Feb 22nd 2009, 8:19 am
lol, sorry.. i clicked the reply button and then wrote the code.. i guess you must have replied in that while..

Cheers.. :)

thefluffball
Feb 22nd 2009, 8:43 am
Ok, fair enough. :p Nothing major either way.

viron86
Feb 22nd 2009, 9:02 am
thank for the i wll try it

rsrikanth05
Feb 22nd 2009, 9:17 am
Thanks a lot, both of you.
I've repped both of you..

thefluffball
Feb 22nd 2009, 12:12 pm
No problem, thanks for that. :)

rsrikanth05
Feb 23rd 2009, 12:23 am
No problem, thanks for that. :)

You're most welcome...
:D