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?
Does that code you posted work? If not, it's probably because browsers disallow modification of iframe content for security reasons.
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
Alternitevely if not sure about the parent element you could do that:
At least this did the job in my case :)
You have lost 1 level, you need modify innerHtml of body, but not document:
You cannot insert into an iframe unless you
remove()
the iframe and use 'append(html)'. You can insert it inside iframes body like