宣传HTML <a> download Attribute

时间:2017-10-17 19:48:55

标签: javascript html promise anchor

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?

0 个答案:

没有答案