Download canvas to Image in IE using Javascript
download, html5-canvas, image, javascript
Solution
Here's what I'm using - not sure what version of IE this requires as I'm using 11. It uses a blob for IE and canvas as a dataURL for other browsers. Tested in Chrome and IE 11.
(canvas is the canvas object, link is an hyperlink object)
if (canvas.msToBlob) { //for IE
var blob = canvas.msToBlob();
window.navigator.msSaveBlob(blob, 'dicomimage.png');
} else {
//other browsers
link.href = canvas.toDataURL();
link.download = "dicomimage.png";
}
Problem
Below code will convert canvas to image and the same is downloaded in browsers other than IE(I'm using IE9).IE Code opens theDataURL in new tab.But,it is not downloadable. ``` if(navigator.appName == "Microsoft Internet Explorer") { somehtml1= document.createElement("img"); somehtml1.id="imgid";somehtml1.name="imgname"; somehtml1.src=canvas.toDataURL("image/png"); document.body.appendChild(somehtml1); window.win = open (somehtml1.src); setTimeout('win.document.execCommand("SaveAs")', 500); } else { somehtml= document.createElement("a"); somehtml.href = canvas.toDataURL("image/png"); somehtml.download = "test.png"; } ```