views:

198

answers:

3

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? Kind regards Massimo

+1  A: 

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

Delan Azabani
The code does not work.This below work.parent.$("#indexIframe")[0].contentDocument.body.innerHTML = "foo";The problem is that since I receive a well formed html with head content I cannot put it in the contentDocument.body.
Massimo Ugues
A: 

Looks like you can get a refrence to the body so I don't see why not:

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_iframe_contentdocument

Ged
No i cannot reference the body: since I have to inject a correct html with head and body:The real html is this:var html = '<html><head><link rel="stylesheet" type="text/css" href="./style.css"/></head><body><p>body</p></body></html>';And if I insert the html in the document.body.innerHTML all the head content is dropped.Kind regards
Massimo Ugues
although undesired in the body under normal circumstances... does it work if you put the `link` tag in the body?
scunliffe
It works with browsers since the browsers do not cut the definition.I receive a problem with the jQuery api clone() with ie6 and the problem is caused by the link tag in the body.Still seeking.... :)
Massimo Ugues
A: 

You have lost 1 level, you need modify innerHtml of body, but not document:

document.body.innerHTML = bla-bla
Dewfy