2017-07-24 13:03:30

Hello,
How can I create a dynamicly generated link? I mean, user clicks on the link, file downloads and the link gets inactive.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2017-07-25 17:41:48

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.

2017-07-25 18:17:34

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>

2017-07-25 23:47:02

Yes, that's basically what I wanted to do. Thanks

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2017-07-27 02:54:06

no problem. I realize upon further reflection, that solution was kind of ugly. Glad you found it somewhat useful.