简体   繁体   English

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

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

I am dynamically creating iframe , which just contains content (no src attribute). 我正在动态创建iframe,其中仅包含内容(无src属性)。

var iframe = document.createElement('iframe');
iframe.contentWindow.document.body.innerHTML=  my_page_content;  
....

however, JS scripts (< script src="....." inside my_page_content ) are not being loaded and I have to re-load scripts. 但是,JS脚本( my_page_content内的< script src="....." )没有被加载,我必须重新加载脚本。

these methods wont help me to reload frame: 这些方法不会帮助我重新加载框架:

//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);

what are the solutions to force the iframe to load the included scripts in its html content? 有什么解决方案可以强制iframe在其html内容中加载包含的scripts maybe I am attaching the content in a wrong way? 也许我以错误的方式附加了内容?

The only way I've solved this was to write the body inside iframe using write() command: 我解决此问题的唯一方法是使用write()命令在iframe中write()主体:

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

neither appendChild() nor .innerHTML helped me. appendChild().innerHTML都没有帮助我。

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

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