Click here to Skip to main content
14,367,095 members
Rate this:
Please Sign up or sign in to 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 4 days ago
v4

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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...
   
v2
Comments
Mayheptad 4 days ago
   
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);
}

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100