[英]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.