Rrz*_*rz0 5 javascript html5 download electron
下面我刚才的问题在这里,
我有一个使用Electron平台和Javascript 的桌面应用程序,我使用以下方法将HTML5画布转换为JPEG:
<a id="download" download="Path.jpg">Download JPG</a>
Run Code Online (Sandbox Code Playgroud)
然后,
function download(){
var dt = canvas.toDataURL('image/jpeg');
this.href=dt;
}
document.getElementById('download').addEventListener('click', download, false);
Run Code Online (Sandbox Code Playgroud)
这刷新了我的整个申请.如何更改此行为,以便在单击下载属性时不刷新页面?
我可以想到这两个片段,一个使用 blob,另一个使用 download 元素。外部库:FileSave.js
// this one use FileSaver.js library
canvas.toBlob(function(blob) {
saveAs(blob, "pretty image.png");
});
// or this way using download element.
// here you can encode your image-data and then send it.
var download = document.getElementById('download');
download.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(imageData));
download.setAttribute('download', 'file.jpg');
Run Code Online (Sandbox Code Playgroud)
我刚刚还发现了这个,电子特定的解决方案: 使用电子在本地保存文件