{"id":2080,"date":"2024-11-10T13:02:56","date_gmt":"2024-11-10T05:02:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2080\/"},"modified":"2024-11-10T13:02:56","modified_gmt":"2024-11-10T05:02:56","slug":"%e5%a6%82%e4%bd%95%e4%bb%8e%e5%b5%8c%e5%a5%97%e7%9a%84-iframe-%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%85%83%e7%b4%a0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2080\/","title":{"rendered":"\u5982\u4f55\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063845358217.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7\u5d4c\u5957 iframe \u83b7\u53d6\u5185\u90e8\u5143\u7d20<\/strong><\/p>\n<p>\u5728 web \u5f00\u53d1\u4e2d\uff0c\u5d4c\u5957\u7684 iframe \u5141\u8bb8\u5728\u4e00\u4e2a\u9875\u9762\u4e2d\u5d4c\u5165\u5176\u4ed6\u9875\u9762\u3002\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u627e\u5230\u5305\u542b\u5916\u90e8 iframe \u7684\u4e3b window \u5bf9\u8c61\uff1a<\/p>\n<pre>const externaliframe = window.frames[\"externaliframename\"];<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u83b7\u53d6\u5d4c\u5957 iframe \u7684 document \u5bf9\u8c61\uff1a<\/p>\n<pre>const nestediframe = externaliframe.document;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6700\u540e\uff0c\u4f7f\u7528 jquery \u6216\u5176\u4ed6\u5e93\u5728\u5d4c\u5957\u7684 iframe \u4e2d\u67e5\u627e\u6240\u9700\u5143\u7d20\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>const element = $(nestedIframe).find(\"#elementId\");<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\u5e76\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\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>\u901a\u8fc7\u5d4c\u5957 iframe \u83b7\u53d6\u5185\u90e8\u5143\u7d20 \u5728 web \u5f00\u53d1\u4e2d\uff0c\u5d4c\u5957\u7684 iframe \u5141\u8bb8\u5728\u4e00\u4e2a\u9875\u9762\u4e2d\u5d4c\u5165\u5176\u4ed6\u9875\u9762\u3002\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a \u9996\u5148\uff0c\u627e\u5230\u5305\u542b\u5916\u90e8 iframe \u7684\u4e3b window \u5bf9\u8c61\uff1a const externaliframe = window.frames[&#8220;externaliframename&#8221;]; \u767b\u5f55\u540e\u590d\u5236 \u63a5\u4e0b\u6765\uff0c\u83b7\u53d6\u5d4c\u5957 iframe \u7684 document \u5bf9\u8c61\uff1a const nestediframe = externaliframe.document; \u767b\u5f55\u540e\u590d\u5236 \u6700\u540e\uff0c\u4f7f\u7528 jquery \u6216\u5176\u4ed6\u5e93\u5728\u5d4c\u5957\u7684 iframe \u4e2d\u67e5\u627e\u6240\u9700\u5143\u7d20\uff0c\u4f8b\u5982\uff1a const element = $(nestedIframe).find(&#8220;#elementId&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\u5e76\u5bf9\u5176\u8fdb\u884c\u64cd\u4f5c\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4ece\u5d4c\u5957\u7684 iframe \u4e2d\u83b7\u53d6\u5143\u7d20\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2080","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2080","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=2080"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2080\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}