繁体   English   中英

重新加载iFrame(相同域)而不更改`src =`

[英]Reload iFrame (same-domain) without changing `src=`

我正在动态创建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 也许我以错误的方式附加了内容?

我解决此问题的唯一方法是使用write()命令在iframe中write()主体:

var ifr = iframeElement.contentWindow.document;
ifr.open(); ifr.write("<body>"+ my_page_content +"</body>");    ifr.close();

appendChild().innerHTML都没有帮助我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM