gpt4 book ai didi

javascript - 指定保存html2canvas到本地的文件名

转载 作者:行者123 更新时间:2023-12-03 04:02:03 25 4
gpt4 key购买 nike

因此,我设法使用 html2canvas 以编程方式保存文件,并且它成功保存了文件。但是,我想指定渲染图像的名称,而不是将其另存为“下载”。那可能吗?我目前的实现方式如下:

html2canvas(document.body, {
onrendered: function(canvas) {
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you dont replace you will get a DOM 18 exception.
window.location.href=image;
}
});

最佳答案

html2canvas(document.body, {
onrendered: function(canvas) {
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you dont replace you will get a DOM 18 exception.
var a = document.createElement('a');
a.href = image;
a.download = 'somefilename.png';
a.click();
}
});

关于javascript - 指定保存html2canvas到本地的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44680517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com