Iframe doesn't stop to loading

2019-07-15 07:01发布

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 ?

2条回答
贪生不怕死
2楼-- · 2019-07-15 07:09

You need to close the iframe connection:

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

I think that this will work.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-07-15 07:23

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

$("#iframe").contents().find("html").html("Test123")
查看更多
登录 后发表回答