如何在iframe中插入html

Mas*_*ues 4 html iframe inject

你好所有:我需要在iframe中插入一个html字符串,如下所示:

....

var html = "<html><head><title>Titolo</title></head><body><p>body</p></body></html>"

jQuery('#popolaIframe').click(function() {
  parent.$("#indexIframe")[0].documentElement.innerHTML = html;     
}); 
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?

小智 6

var html = "<html><head><title>Titolo</title></head><body><p>body</p></body></html>"

jQuery('#popolaIframe').click(function() {
  var doc = parent.$("#indexIframe")[0].documentElement;
  doc.open();
  doc.write(html);
  doc.close();     
}); 
Run Code Online (Sandbox Code Playgroud)

  • 我无法弄清楚这个解决方案,这里有类似的东西对我有用:mydoc = document.getElementById('iframe_id').contentWindow.document; mydoc.write(html_code); mydoc.close(); (3认同)