Replace Entire Content of Iframe

前端 未结 4 1144
鱼传尺愫
鱼传尺愫 2020-12-29 08:11

Is there a way to replace the ENTIRE contents of an iframe using Javascript (or Jquery)?

For example if my iframe had the following content...

blah o         


        
4条回答
  •  萌比男神i
    2020-12-29 08:16

    I'm guessing that you're not having problems with cross-site scripting in this instance... Have you had any luck using contentWindow? Something like this seems to work well enough for me:

    iframe = document.getElementById('iframe_id');
    iframe.contentWindow.document.open()
    iframe.contentWindow.document.write(new_content_here);
    

    Not my idea, found it here: Write elements into a child iframe using Javascript or jQuery

提交回复
热议问题