change saveFile. attempting to fix for iOS

This commit is contained in:
Danny Coates 2018-02-14 09:29:37 -08:00
parent a82688163e
commit c0ad7635f2
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 17 additions and 7 deletions

View File

@ -142,19 +142,29 @@ function fadeOut(id) {
}
function saveFile(file) {
const reader = new FileReader();
const dataView = new DataView(file.plaintext);
const blob = new Blob([dataView], { type: file.type });
const downloadUrl = URL.createObjectURL(blob);
if (window.navigator.msSaveBlob) {
return window.navigator.msSaveBlob(blob, file.name);
}
const a = document.createElement('a');
a.href = downloadUrl;
a.download = file.name;
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(downloadUrl);
reader.addEventListener('loadend', function() {
if (reader.result) {
const a = document.createElement('a');
a.href = reader.result;
a.download = file.name;
document.body.appendChild(a);
a.click();
return;
}
if (reader.error) {
console.error(reader.error);
window.location.href = '/error';
//TODO
}
});
reader.readAsDataURL(blob);
}
function openLinksInNewTab(links, should = true) {