Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert html in iframe

Hallo all: I need to insert a html string in a iframe as shown below:

....

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

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

Is there a way to achieve this?

like image 600
Massimo Ugues Avatar asked May 06 '10 12:05

Massimo Ugues


2 Answers

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();     
}); 
like image 106
omtester Avatar answered Oct 16 '22 09:10

omtester


Does that code you posted work? If not, it's probably because browsers disallow modification of iframe content for security reasons.

like image 36
Delan Azabani Avatar answered Oct 16 '22 09:10

Delan Azabani