Skip to content

Commit 129a881

Browse files
authoredFeb 18, 2020
Merge pull request #57 from guoqchen1001/master
fix bug window.URL.createObjectURL is not a function
2 parents 77f0db7 + c2304eb commit 129a881

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎file-download.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ module.exports = function(data, filename, mime, bom) {
22
var blobData = (typeof bom !== 'undefined') ? [bom, data] : [data]
33
var blob = new Blob(blobData, {type: mime || 'application/octet-stream'});
44
if (typeof window.navigator.msSaveBlob !== 'undefined') {
5-
// IE workaround for "HTML7007: One or more blob URLs were
6-
// revoked by closing the blob for which they were created.
7-
// These URLs will no longer resolve as the data backing
5+
// IE workaround for "HTML7007: One or more blob URLs were
6+
// revoked by closing the blob for which they were created.
7+
// These URLs will no longer resolve as the data backing
88
// the URL has been freed."
99
window.navigator.msSaveBlob(blob, filename);
1010
}
1111
else {
12-
var blobURL = window.URL.createObjectURL(blob);
12+
var blobURL = (window.URL ? window.URL : window.webkitURL).createObjectURL(blob);
1313
var tempLink = document.createElement('a');
1414
tempLink.style.display = 'none';
1515
tempLink.href = blobURL;
16-
tempLink.setAttribute('download', filename);
17-
16+
tempLink.setAttribute('download', filename);
17+
1818
// Safari thinks _blank anchor are pop ups. We only want to set _blank
1919
// target if the browser does not support the HTML5 download attribute.
20-
// This allows you to download files in desktop safari if pop up blocking
20+
// This allows you to download files in desktop safari if pop up blocking
2121
// is enabled.
2222
if (typeof tempLink.download === 'undefined') {
2323
tempLink.setAttribute('target', '_blank');
2424
}
25-
25+
2626
document.body.appendChild(tempLink);
2727
tempLink.click();
28-
28+
2929
// Fixes "webkit blob resource error 1"
3030
setTimeout(function() {
3131
document.body.removeChild(tempLink);

0 commit comments

Comments
 (0)
Please sign in to comment.