user3774686
user3774686

Reputation: 61

document.getElementById('a').click() doesn't works in IE

I have a code which worked in Chrome and Firefox but not work in IE. It downloads a file stored in a mysql db as a blob record by a link.

Could anyone propose a solution that also works in IE?

The code:

function download(filename, data) {


var a = document.createElement("a");


var blob = b64toBlob(data, "application/octet-stream");

url = window.URL.createObjectURL(blob);

a.href = url;

a.download = filename;

a.click();

document.getElementById('a').click();

window.URL.revokeObjectURL(url);

}

Upvotes: 0

Views: 2649

Answers (1)

user3774686
user3774686

Reputation: 61

In IE 8 and 9, data URIs can only be used for images, but not for navigation or JavaScript generated file downloads:

function download(filename, data) {

var a = document.createElement("a");
var blob = b64toBlob(data, "application/octet-stream");
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
navigator.msSaveBlob(blob, filename);
//document.getElementById('a').onclick();
window.URL.revokeObjectURL(url);

}

Upvotes: 4

Related Questions