putting html inside an iframe (using javascript)

前端 未结 6 650
执笔经年
执笔经年 2020-11-27 04:10

Can I create an empty iframe as a placeholder to later insert html into it?

In otherwords, suppose I have an empty iframe with an id,

How do I insert html i

6条回答
  •  感动是毒
    2020-11-27 04:36

    You can do it without jQuery also:

    var iframe = document.getElementById('iframeID');
    iframe = iframe.contentWindow || ( iframe.contentDocument.document || iframe.contentDocument);
    
    iframe.document.open();
    iframe.document.write('Hello World!');
    iframe.document.close();
    

    jQuery's html strips body, html and head tags from the inserted HTML.

提交回复
热议问题