Sunday, October 12, 2008

Inject html string into a iframe

var text = "<div id='storeArea'>test</div>";
var content = "<html><body>" + text + "</body></html>";
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);

var doc = iframe.document;
if(iframe.contentDocument)
doc = iframe.contentDocument; // For NS6
else if(iframe.contentWindow)
doc = iframe.contentWindow.document; // For IE5.5 and IE6

// Put the content in the iframe
doc.open();
doc.writeln(content);
doc.close();
// Load the content into a TiddlyWiki() object
var storeArea = doc.getElementById("storeArea");
console.log(storeArea);

Reference:
http://softwareas.com/injecting-html-into-an-iframe

No comments :