如果您使用FileSaver.js,它将在Edge上下载。对于使用FileSaver.js,您需要将base64数据转换为blob数据。要做到这一点,请this post on StackOverflow
这里是一个更新的fiddle
您需要包括FileSaver.js到你的项目,你的保存按钮就会有下面的代码:
$("#canvas2png").click(function(){
canvas.isDrawingMode = false;
if(!window.localStorage){alert("This function is not supported by your browser."); return;}
var blob = new Blob([b64toBlob(canvas.toDataURL('png').replace(/^data:image\/(png|jpg);base64,/, ""),"image/png")], {type: "image/png"});
saveAs(blob, "testfile1.png");
});
替代,快速和肮脏的解决方案是将html数据写入新标签,并右键单击图像并保存。这个解决方案不需要任何插件或库。
保存将会简单地更改为:
$("#canvas2png").click(function(){
canvas.isDrawingMode = false;
if(!window.localStorage){alert("This function is not supported by your browser."); return;}
var html="<img src='"+canvas.toDataURL()+"' alt='canvas image'/>";
var newTab=window.open();
newTab.document.write(html);
});
我相信这是由于CORS问题。请看看filesaver.js(这是在边缘IE工作) – Observer