
html2canvas 出现 “unable to find element in cloned iframe” 错误
使用 html2canvas 和 jspdf 时出现错误 “Uncaught (in promise) Unable to find element in cloned iframe”?这是由于 html2canvas 无法找到要转换的元素。
问题示例:
let div = document.createdElement('div');
div.id = 'pagess';
div.innerHTML = "Hi there!";
document.body.append(div);
const promise = new Promise((res, rej) => {
html2canvas(div, { useCORS: true }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new JsPDF();
pdf.addImage(imgData, 'png', 100, 100);
pdf.save('hello.pdf');
}).catch(error => {
rej(error);
})
});解决方案:
第一行代码中有错误。正确的写法应该是:
立即学习“前端免费学习笔记(深入)”;
let div = document.createElement('div');











