I'm using the following code to trigger a download from a href:
function save(href, download) {
let element = document.createElement('a');
element.setAttribute('href', href);
element.setAttribute('download', download);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
I'd like to listen to the download-event, mainly having a promise around save(), so that I can see whether or not the user clicked on save
or cancel
in a (resolve, reject) promise mapping.
Any way to do this?