Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello coders in the house.
I am a complete beginner, i saw something on thewpclub. Net and i want to implement the same on my WordPress blog.

When someone click a download link, i want another browser tab to open and display a countdown timer like 15 seconds before the main download link will now appear.

Pls try and download from thewpclub. Net , you will understand what am trying to say.

What I have tried:

A friend on facebook gave me this jquery code.

But after i paste it in my blog.
The countdown just happen righaway on the same post page. It doesnt even wait for user to click the link not to talk of opening a new tab.


See the code below

jQuery code:
function c(){
var startTime = $('.c').attr('id');
var counter = startTime;
$('.c').text(counter);
setInterval(function() {
counter--;
if (counter > 0) {
$('.c').text(counter);
}
// Display 'counter' wherever you want to display it.
if (counter === 0) {
// alert('this is where it happens');
clearInterval(counter);
$('.c').text('');
$('.c').append('<a href="#">Download</a>');
}
}, 1000);
}
// Start
c();
HTML:
<span class="c" id="5"></span>
Posted
Updated 12-Sep-22 13:47pm
v4

0) The delay does not go on the page where the user clicked the link - it goes on the page that has the download button.

1) To make a link open in a new tab, add target="_top" to the href.

2) You should respond to an event in order for the html to be rendered.

3) For the record, these arbitrary download delays annoy the f*ck outa me. Just sayin...
 
Share this answer
 
v2
Comments
Bill Mayheptad Ritchie 17-Nov-19 17:40pm    
thanks, @realjsop.
I added target="_top" to the href still the link does not open in new tab.
so I added target="_blank" to the href and it is now opening in a new tab.
I also added an onClick event to the HTML span tag where I want the user to click before the download redirection occurs.

but still, the countdown still happens right there on the same page, whereas I want a new browser tab to open when I click on the link in the Html span tag, and in that new browser tab is where I want the countdown to happen before it will finally display the actual download link.

I want to do it exactly how thewpclub. net did it.
please help.

And if it is not possible to do it with javascript, if it is PHP somebody should please write the PHP code for me

SEE MY CODE BELOW AND TELL ME WHAT AM DOING WRONG

HTML
<span class="c" id="5"><a href="ADDRESS OF PAGE WHERE I WANT THE COUNTDOWN TO HAPPEN" target="_blank"></a></span>


jQUERY

function c(){
var startTime = $('.c').attr('id');
var counter = startTime;
$('.c').text(counter);
setInterval(function() {
counter--;
if (counter > 0) {
$('.c').text(counter);
}
// Display 'counter' wherever you want to display it.
if (counter === 0) {
// alert('this is where it happens');
clearInterval(counter);
$('.c').text('');
$('.c').append('<a href="ACTUAL FILE DOWNLOAD LINK" target="_blank">Download</a>');
}
}, 1000);
}

I Have this same question and i found a lot but didn’t fount the correct answer , pleeease let me know if you got any solution.
 
Share this answer
 
v2
Comments
Richard Deeming 15-Sep-22 6:02am    
"Me too" is not a solution to anyone's question.

If you want to ask a question, then ASK A QUESTION[^] - but you'll need to provide a lot more information if you want anyone to help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900