How to set HTML content into an iframe

前端 未结 6 1768
醉酒成梦
醉酒成梦 2020-11-28 07:16

I have a HTML string


  Hello world
 

and I wan

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 07:54

    You could use:

    document.getElementById('iframe1').contentWindow.document.write("Hello world");
    

    Here's a jsFiddle, which works in all major browsers.

    Note that instead of contentDocument.write you should use contentWindow.document.write: this makes it work in IE7 as well.

提交回复
热议问题