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

花韻仙語
发布: 2024-11-06 22:48:49
原创
282人浏览过

使用 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” 错误?的详细内容,更多请关注php中文网其它相关文章!

WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号