【发布时间】:2022-01-25 12:29:38
【问题描述】:
JavaScript 新手,请帮我在 html2canvas 脚本中渲染外部图像。我必须使用useCORS 吗?如果是,在哪里?我也尝试过从 css 和 html 标签渲染图像,但它没有反映。
还有控制台错误:Uncaught (in promise) DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
const elm = document.querySelector(".convert");
html2canvas(elm).then(function(canvas) {
document.querySelector(".result");
document.body.appendChild(canvas);
let cvs = document.querySelector("canvas");
let a = document.querySelector(".a");
a.href= cvs.toDataURL();
a.download="example.png";
});
【问题讨论】: