Iframe doesn't stop to loading

徘徊边缘 提交于 2019-12-24 04:25:47

问题


As answered in this post, I'm trying to set an Iframe's content with :

document.getElementById("iframe").contentDocument.write("Test123");

The problem is that even though everything seems to work (the Iframe is displaying Test123), the browser doesn't stop loading. Indeed, in Firefox's tab it's written "Connecting ..." with the spinner indicating it's still loading.

Why does it happen ? Is there a better solution to set an Iframe's content ?


回答1:


You need to close the iframe connection:

document.getElementById("iframe").contentDocument.close();

I think that this will work.




回答2:


Try doing it with jQuery, it might solve your issue and it is much cleaner:

$("#iframe").contents().find("html").html("Test123")


来源:https://stackoverflow.com/questions/18466983/iframe-doesnt-stop-to-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!