diff --git a/src/utils/file/download.ts b/src/utils/file/download.ts index 168e235..6674ec3 100644 --- a/src/utils/file/download.ts +++ b/src/utils/file/download.ts @@ -36,22 +36,18 @@ export function downloadByBase64(buf: string, filename: string, mime?: string, b export function downloadByData(data: BlobPart, filename: string, mime?: string, bom?: BlobPart) { const blobData = typeof bom !== 'undefined' ? [bom, data] : [data]; const blob = new Blob(blobData, { type: mime || 'application/octet-stream' }); - if (typeof window.navigator.msSaveBlob !== 'undefined') { - window.navigator.msSaveBlob(blob, filename); - } else { - const blobURL = window.URL.createObjectURL(blob); - const tempLink = document.createElement('a'); - tempLink.style.display = 'none'; - tempLink.href = blobURL; - tempLink.setAttribute('download', filename); - if (typeof tempLink.download === 'undefined') { - tempLink.setAttribute('target', '_blank'); - } - document.body.appendChild(tempLink); - tempLink.click(); - document.body.removeChild(tempLink); - window.URL.revokeObjectURL(blobURL); + const blobURL = window.URL.createObjectURL(blob); + const tempLink = document.createElement('a'); + tempLink.style.display = 'none'; + tempLink.href = blobURL; + tempLink.setAttribute('download', filename); + if (typeof tempLink.download === 'undefined') { + tempLink.setAttribute('target', '_blank'); } + document.body.appendChild(tempLink); + tempLink.click(); + document.body.removeChild(tempLink); + window.URL.revokeObjectURL(blobURL); } /**