Hello folks I do not understand pretty much anything from Javascript, so for weeks I was trying to make a script that would do the following:
00:00:00
1st started a countdown of 20 minutes after clicking on a link.
2nd And at the same time redirect to a website.
3º on passing the 20 minutes the clock would be at zero so 00:00:00 so that the user clicked and started counting again and redirected to the post-click site.
(Remember that redirects after clicking and not after finishing the count!)
4th And I had cookies to continue counting even after refreshing the page!
I could not do this, but I found a script that does almost everything listed above. The only problem with the script is that it does not have the link to click and start counting and does not even have the cookie code to continue even after refreshing the page! See the code below and if you know what I can do to put the link to be clicked and the code of cookies
<html><head> <script language="javaScript">
var min, seg; min = 20; seg = 1
function relogio(){
if((min > 0) || (seg > 0)){
if(seg == 0){
seg = 59;
min = min - 1
}
else{
seg = seg - 1;
}
if(min.toString().length == 1){
min = "0" + min;
}
if(seg.toString().length == 1){
seg = "0" + seg;
}
document.getElementById('spanRelogio').innerHTML = min + ":" + seg;
setTimeout('relogio()', 1000);
}
else{
document.getElementById('spanRelogio').innerHTML = "00:00";
}
}
</script></head><body style="font-family:verdana;font-size:10px;" onLoad="relogio()"> <span id="spanRelogio"></span></body></html>
People I gave a change in the script and can put the link, but it happens that after the count is finished it gets stuck at 00:00 and clicking again does not start the count again (I changed it to 1 minute to be faster) ↓
<script language="javaScript">
var min, seg; min = 1; seg = 1
function relogio(){
if((min > 0) || (seg > 0)){
if(seg == 0){
seg = 59;
min = min - 1
}
else{
seg = seg - 1;
}
if(min.toString().length == 1){
min = "0" + min;
}
if(seg.toString().length == 1){
seg = "0" + seg;
}
document.getElementById('spanRelogio').innerHTML = min + ":" + seg;
setTimeout('relogio()', 1000);
}
else{
document.getElementById('spanRelogio').innerHTML = "00:00";
}
}
</script>
<a href="http://pt.stackoverflow.com/" onClick="relogio(event)" target="_blank">Clique Aqui</a>
<span id="spanRelogio"></span>