【发布时间】:2018-05-23 16:39:08
【问题描述】:
我正在动态创建 iframe ,它只包含内容(没有 src 属性)。
var iframe = document.createElement('iframe');
iframe.contentWindow.document.body.innerHTML= my_page_content;
....
但是,JS 脚本(my_page_content 内的 script src=".....")没有被加载,我必须重新加载脚本。
这些方法无法帮助我重新加载框架:
//this one emptyfies the iframe at all
iframeElement.src = iframeElement.src
//this one is not possible, because the `<script>` links are embedded in the content already.
var script = doc.createElement('script'); script.src = "jquery.min.js";
framebody.appendChild(script);
强制 iframe 在其 html 内容中加载包含的 scripts 的解决方案是什么?也许我以错误的方式附加内容?
【问题讨论】:
-
脚本是否在它们引用的 html 之后?可疑问题与加载事件有关。创建一个重现问题的minimal reproducible example
-
@charlietfl ,谢谢,我现在找到了解决方案,并在下面发布了。
标签: javascript php jquery iframe frame