sheetaki/src/downloadFile.js

10 lines
427 B
JavaScript
Raw Normal View History

2021-05-06 23:51:42 +00:00
//creates link to download a file. then clicks link automatically. then removes link
module.exports = function (url, filename) {
var a = document.createElement("a");
a.download = filename;
a.href = url;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
if (URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function () { URL.revokeObjectURL(url); }, 60000);
}