{"id":26398,"date":"2024-11-24T09:16:44","date_gmt":"2024-11-24T01:16:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26398\/"},"modified":"2024-11-24T09:16:44","modified_gmt":"2024-11-24T01:16:44","slug":"%e4%bd%bf%e7%94%a8-html2canvas-%e5%92%8c-jspdf-%e6%97%b6%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-unable-to-find-element-in-cloned-iframe-%e9%94%99%e8%af%af%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26398\/","title":{"rendered":"\u4f7f\u7528 html2canvas \u548c jspdf \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 \u201cUnable to find element in cloned iframe\u201d \u9519\u8bef\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173090453139423.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 html2canvas \u548c jspdf \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 \u201cUnable to find element in cloned iframe\u201d \u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 html2canvas \u548c jspdf \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 \u201cUnable to find element in cloned iframe\u201d \u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>html2canvas \u51fa\u73b0 \u201cunable to find element in cloned iframe\u201d \u9519\u8bef<\/strong><\/p>\n<p>\u4f7f\u7528 html2canvas \u548c jspdf \u65f6\u51fa\u73b0\u9519\u8bef \u201cUncaught (in promise) Unable to find element in cloned iframe\u201d\uff1f\u8fd9\u662f\u7531\u4e8e html2canvas \u65e0\u6cd5\u627e\u5230\u8981\u8f6c\u6362\u7684\u5143\u7d20\u3002<\/p>\n<p>\u95ee\u9898\u793a\u4f8b\uff1a<\/p>\n<pre>let div = document.createdElement('div');\ndiv.id = 'pagess';\ndiv.innerHTML = \"&lt;strong&gt;Hi there!&lt;\/strong&gt;\";\ndocument.body.append(div);\nconst promise = new Promise((res, rej) =&gt; {\n  html2canvas(div, { useCORS: true }).then(canvas =&gt; {\n    const imgData = canvas.toDataURL('image\/png');\n    const pdf = new JsPDF();\n    pdf.addImage(imgData, 'png', 100, 100);\n    pdf.save('hello.pdf');\n  }).catch(error =&gt; {\n    rej(error);\n  })\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u7b2c\u4e00\u884c\u4ee3\u7801\u4e2d\u6709\u9519\u8bef\u3002\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>let div = document.createElement('div');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528 html2canvas \u548c jspdf \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 \u201cUnable to find element in cloned iframe\u201d \u9519\u8bef\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>html2canvas \u51fa\u73b0 \u201cunable to find element in cloned iframe\u201d \u9519\u8bef \u4f7f\u7528 html2canvas \u548c jspdf \u65f6\u51fa\u73b0\u9519\u8bef \u201cUncaught (in promise) Unable to find element in cloned iframe\u201d\uff1f\u8fd9\u662f\u7531\u4e8e html2canvas \u65e0\u6cd5\u627e\u5230\u8981\u8f6c\u6362\u7684\u5143\u7d20\u3002 \u95ee\u9898\u793a\u4f8b\uff1a let div = document.createdElement(&#8216;div&#8217;); div.id = &#8216;pagess&#8217;; div.innerHTML = &#8220;&lt;strong&gt;Hi there!&lt;\/strong&gt;&#8221;; document.body.append(div); const promise = new Promise((res, rej) =&gt; { html2canvas(div, { useCORS: true }).then(canvas =&gt; { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26398","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26398"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26398\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}