I had to create an inline frame to show description part of eBay item.

First, I wrote following JavaScript code. But it didn’t work when content of iframe contains some JavaScript code.

var iframe = $('<iframe></iframe>').attr('src', '/blank.html');

iframe.load(function() {
    $(this).contents().find('body').append(some_code);
});

$('#iframewrapper').replaceWith(iframe);

I found working code in “jwysiwyg” rich html editor project. Following code fixed my problem.

var iframe = $('<iframe></iframe>').attr('src', '/blank.html');

iframe.load(function() {
    $(this).get(0).contentWindow.document.write(some_code);
});

$('#iframewrapper').replaceWith(iframe);