My page generates a URL like this: blob:http%3A//localhost%3A8383/568233a1-8b13-48b3-84d5-cca045ae384f
, blob having file data. I am downloading this as a file in every browser except IE 11. How can I download this blob in IE 11? A new tab get open and continuous refreshing happen.
var file = new Blob([data], { type: 'application/octet-stream' });
var reader = new FileReader();
reader.onload = function (e) {
var text = reader.result;
}
reader.readAsArrayBuffer(file);
var fileURL = URL.createObjectURL(file);
var filename = fileURL.replace(/^.*[\\\/]/, '');
var name = filename + '.doc';
var a = $("<a style='display: none;'/>");
a.attr("href", fileURL);
a.attr("download", name);
$("body").append(a);
a[0].click();
a.remove();
For inside iframe download in Internet Explorer 11, you need to use parent. window. navigator. msSaveOrOpenBlob(blob, "filename.
The blob URI scheme, also known as an object URL, is a Uniform Resource Identifier (URI) scheme used for accessing locally generated data via APIs designed to work only with URLs.
createObjectURL() static method creates a string containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object. To release an object URL, call revokeObjectURL() .
IE11 Not support URL.createObjectURL()
Work for me.
IE11 I'm use
window.navigator.msSaveOrOpenBlob(blob, fileName);
Or, If check condition.
var blob = 'Blob Data';
if(window.navigator.msSaveOrOpenBlob) {
// IE11
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
// Google chome, Firefox, ....
var url = (window.URL || window.webkitURL).createObjectURL(blob);
$('#filedownload').attr('download', fileName);
$('#filedownload').attr('href', url);
$('#filedownload')[0].click();
}
Read more: Fixed URL.createObjectURL() function doesn't work in IE 11
Demo: JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With