Hello,
How can I create a dynamicly generated link? I mean, user clicks on the link, file downloads and the link gets inactive.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com
You are not logged in. Please login or register.
AudioGames.net Forum → Developers room → JS question: how to create dynamicly generated link?
Hello,
How can I create a dynamicly generated link? I mean, user clicks on the link, file downloads and the link gets inactive.
Warning: this is java script just no jquery.
My solution would be to try an onclick event or add an event listener
and in that onclick or event listener, you can set the href attribute of the link to be an empty string.
I will try it myself now.
Is this what you want to do?
This is an example of what you might want to do. This uses an event listener look at the link and at the script tag.
For best results, use closer to a modern browser.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<a id="specialLink" href="thingToDownload.txt" download >Thing to download</a>
</body>
<script>
var specialLink = document.getElementById("specialLink");
var numClicks = 0; //this will count number of clicks
specialLink.addEventListener("click", function() {
if (numClicks>=1) { //if somebody clicked the link once, the href attribute will become a random string
specialLink.setAttribute("href", "fe");
specialLink.setAttribute("aria-disabled");
}
numClicks = numClicks+1;
});
</script>
</html>
Yes, that's basically what I wanted to do. Thanks
no problem. I realize upon further reflection, that solution was kind of ugly. Glad you found it somewhat useful.
AudioGames.net Forum → Developers room → JS question: how to create dynamicly generated link?
Generated in 0.016 seconds (50% PHP - 50% DB) with 9 queries