使用 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 出现 “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 = "<strong>Hi there!</strong>";
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学习网公众号了解相关技术文章。
相关阅读
更多>
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
325 收藏
-
405 收藏
-
413 收藏
-
293 收藏
-
356 收藏
-
119 收藏
-
182 收藏
-
288 收藏
-
120 收藏
-
392 收藏
-
321 收藏
-
2. CSS 样式使用 ::after 伪元素来在图片上叠加文字:
.im" class="aBlack">CSS图片上叠加文字的实现方法,主要通过使用伪元素(如 ::after)来在图片上方添加内容。以下是详细步骤和示例代码:1. HTML 结构假设你有一个包含图片的容器,结构如下:2. CSS 样式使用 ::after 伪元素来在图片上叠加文字: .im
318
收藏