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();
In IE try
window.navigator.saveBlob(fileURL,name);
.For further information take a look at the documentation at MSDN.
In the past I've created the following really handy polyfill to check on IE and otherwise use downloading via
href
. Maybe it will help you (or others):You can then use this anywhere in your app as simple as:
Fidel90's answer works fine in IE 11 after changing the IE specific part to this:
IE11 Not support URL.createObjectURL()
Work for me.
IE11 I'm use
Or, If check condition.
Read more: Fixed URL.createObjectURL() function doesn't work in IE 11
Demo: JSFiddle