Created
February 27, 2018 12:23
-
-
Save noherczeg/5799d9e3e3f49f30e94b35fed90ff53a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var filename = ""; | |
var type = xhr.getResponseHeader('Content-Type'); | |
var blob = new Blob([response], {type: type}); | |
var URL = window.URL || window.webkitURL; | |
var downloadUrl = URL.createObjectURL(blob); | |
if (filename) { | |
// use HTML5 a[download] attribute to specify filename | |
var a = document.createElement("a"); | |
// safari doesn't support this yet | |
if (typeof a.download === 'undefined') { | |
window.location = downloadUrl; | |
} else { | |
a.href = downloadUrl; | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
} | |
} else { | |
window.location = downloadUrl; | |
} | |
setTimeout(function () { | |
URL.revokeObjectURL(downloadUrl); | |
}, 100); // cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment