登录
首页 >  文章 >  前端

使用 html2canvas 和 jspdf 时,如何解决 “Unable to find element in cloned iframe” 错误?

时间:2024-11-06 18:12:53 152浏览 收藏

最近发现不少小伙伴都对文章很感兴趣,所以今天继续给大家介绍文章相关的知识,本文《使用 html2canvas 和 jspdf 时,如何解决 “Unable to find element in cloned iframe” 错误? 》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

使用 html2canvas 和 jspdf 时,如何解决 “Unable to find element in cloned iframe” 错误?

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');

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《使用 html2canvas 和 jspdf 时,如何解决 “Unable to find element in cloned iframe” 错误? 》文章吧,也可关注golang学习网公众号了解相关技术文章。

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>