Set iframe innerHTML without loading page in it (with jquery)
If you want to avoid using document.write
, which is generally not recommended any longer, you can get at the frame contents to add the content:
iframe = $('<iframe id="thepage"></iframe>')
iframeHtml = 'iframeHtml'
$('body').append(iframe)
iframe.contents().find('body').html(iframeHtml)
the best way to populate frame contents is document.write
var dstFrame = document.getElementById('yourFrameId');
var dstDoc = dstFrame.contentDocument || dstFrame.contentWindow.document;
dstDoc.write(yourHTML);
dstDoc.close()
UPD: that is
var iFrame = $('<iframe id="thepage"></iframe>');
$('body').append(iFrame);
var iFrameDoc = iFrame[0].contentDocument || iFrame[0].contentWindow.document;
iFrameDoc.write('<p>Some useful html</p>');
iFrameDoc.close();