Skip to content

Instantly share code, notes, and snippets.

@daanta-real
Created June 23, 2022 06:23
Show Gist options
  • Save daanta-real/af3d247299bc36779114c5d305ff9280 to your computer and use it in GitHub Desktop.
Save daanta-real/af3d247299bc36779114c5d305ff9280 to your computer and use it in GitHub Desktop.
File download function for modern browsers ( = excluding IE)
function downloadExecute(downloadURL) {
fetch(downloadURL)
.then(function(response) {
return response.blob();
}).then(function(blob) {
var fileBlob = new Blob([blob], {type: blob.type});
var aLink = document.createElement("a");
aLink.href = window.URL.createObjectURL(fileBlob);
aLink.download = decodeEntity(pageData.fileName);
aLink.click();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment