Countdown timer to unlock link

If you want code a page countdown time to show link you cant use this code by java script and dom.

<span id=”countdown”></span>
<a id=”download_link” href=”http://www.google.com” style=”display:none;”>Continue</a>
<noscript>JavaScript needs to be enabled in order to be able to continue.</noscript>
<script type=”application/javascript”>
(function(){
var message = “%d seconds before you can continue”;
// seconds before link becomes visible
var count = 20;
var countdown_element = document.getElementById(“countdown”);
var download_link = document.getElementById(“download_link”);
var timer = setInterval(function(){
// if countdown equals 0, the next condition will evaluate to false and the else-construct will be executed
if (count) {
// display text
countdown_element.innerHTML = “You have to wait %d seconds.”.replace(“%d”, count);
// decrease counter
count–;
} else {
// stop timer
clearInterval(timer);
// hide countdown
countdown_element.style.display = “none”;
// show link
download_link.style.display = “”;
}
}, 1000);
})();
</script>

Good luck!

Giới thiệu honest 237 bài viết
Mình lập blog này với mục đích lưu lại + chia sẻ các các kiến thức mình đã biết hoặc đang tìm hiểu. Cơ bản giúp ích cho mình :) Nhưng hy vọng sẽ mang lại sự khởi đầu thuận lợi cho người mới bắt đầu!