I have a jQuery snippet as below:
$.ajax({
....
success: function(myContent) {
.....
$('<iframe id="myFrame" name="myFrame">').appendTo('body').ready(function(){
$('#myFrame').contents().find('body').append(myContent);
});
.....
});
});
When the event is triggered at the first time, only an empty iframe displays, but if the event is triggered at the second time, content is appended into the iframe successfully. Any obvious error in this snippet?
This simple code may be use for you, it works fine for me.
I believe some browsers need a short delay for it to recognize the DOM of a new iframe. Using a timeout should work:
I think this is what you are looking for:
Demo: http://jsfiddle.net/vbNGA/1/