I have the following code. I need to convert canvas element in to image format and need to save. So i did the following in my script
exportImage: function (fileName, fileType) {
var lnk = document.createElement('a'), e;
lnk.download = fileName + "." + fileType;
lnk.href = this.canvasElement.toDataURL("image/" + fileType).replace("image/" + fileType, "image/octet-stream");
if (document.createEvent) {
e = document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
lnk.dispatchEvent(e);
}
else if (lnk.fireEvent) {
lnk.fireEvent("onclick");
}
},
But this code works fine in the firefox. But given file name is not set in chrome. And even save is not working in the IE.