Skip to content
Snippets Groups Projects
Commit 28cda953 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Allow some kind of downloading to work on Safari

parent 593c3448
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,23 @@ export default (filename, blob) => {
return;
}
const url = window.URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.download = filename;
downloadLink.type = blob.type;
downloadLink.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(downloadLink);
if ('download' in HTMLAnchorElement.prototype) {
const url = window.URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.download = filename;
downloadLink.type = blob.type;
downloadLink.click();
document.body.removeChild(downloadLink);
window.URL.revokeObjectURL(url);
} else {
// iOS Safari, open a new page and set href to data-uri
let popup = window.open('', '_blank');
const reader = new FileReader();
reader.onloadend = function () {
popup.location.href = reader.result;
popup = null;
};
reader.readAsDataURL(blob);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment