When I set the script on the head the script works properly. But when i put the script directly in the HTML the script doesn't work
const downloadBtn = document.querySelector(“.download-btn”);
const fileLink = "<?php echo $article->file?>";
const initTimer = () => {
if(downloadBtn.classList.contains("disableTimer")) {
return location.href = fileLink;
}
let timer = downloadBtn.dataset.timer;
downloadBtn.classList.add("timer");
downloadBtn.innerHTML = `Your files will download in <b>${timer}</b> seconds`;
const initCounter = setInterval(() => {
if(timer > 0) {
timer--;
return downloadBtn.innerHTML = `Your files will download in <b>${timer}</b> seconds`;
}
clearInterval(initCounter);
location.href = fileLink;
downloadBtn.innerText = "Se están descargando los archivos";
setTimeout(() => {
downloadBtn.classList.replace("timer", "disableTimer");
downloadBtn.innerHTML = `<span class="icon material-symbols-rounded">vertical_align_bottom</span>
<span class="text">Download again</span>`;
}, 3000);
}, 1000);
}
downloadBtn.addEventListener("click", initTimer);
</script>`
I tried doing setting a link instead of the php but it doesn’t work
New contributor
Quelopande is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.