const download = (fileUrl, filename) => {
fetch(fileUrl)
.then(response => response.blob())
.then(data => {
const tempUrl = URL.createObjectURL(data);
const link = document.createElement('a');
link.href = tempUrl;
link.download = filename;
link.addEventListener('click', () => {
setTimeout(() => {
URL.revokeObjectURL(tempUrl);
});
});
link.click();
});
};
window.addEventListener('DOMContentLoaded', () => {
download('MY_URL', 'MY_FILENAME.txt');
});