<a href="#" onclick="onDownload(event)">Download</a>
<a href="#" id="fileLink" hidden download="file.txt"></a>
function onDownload(e) {
e.preventDefault();
const link = createFile("some text content");
fileLink.href = link;
fileLink.click();
}
function createFile(text) {
const textBlob = new Blob([text], { type: "text/plain" });
return window.URL.createObjectURL(textBlob);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.