I am downloading the image. It is only working in Chrome not in Firefox or IE.
var a = document.createElement('a');
a.href = canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
a.download = 'Post-ITIE.jpg';
a.click()
Can anyone help me how can it be working for all browsers.
Help would be highly appreciated. Thanks
var fileName = 'Post-ITIE.jpg';
if ('msToBlob' in canvas) { // IE10+
var blob = canvas.msToBlob();
navigator.msSaveBlob(blob, fileName);
} else {
var a = document.createElement('a');
a.setAttribute('href', canvas.toDataURL());
a.setAttribute('target', '_blank');
a.setAttribute('download', fileName);
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
It does a couple of thing differently than the code originally provided:
msToBlob
method is present to support downloading the file in Internet Explorer.target=blank
to the link element. This makes sure that the image is displayed, even if the browser doesn't support the download
attribute..click()
actually works in Firefox and removes it afterwards.