문제

Can anyone please help me identify why this iframe behaves differently in Chrome vs Firefox?

$('<iframe id="iframe1"></iframe>').appendTo($('.main')).contents().find('html').html("<h1 style='text-align: center;'>This IS an iframe</h1>");

http://jsfiddle.net/ioowilly/L9uAX/

도움이 되었습니까?

해결책

or try this

$('<iframe id="iframe1" src="javascript:undefined;" ></iframe>').appendTo($('.main')).contents().find('body').html("<h1 style='text-align: center;'>This IS an iframe</h1>");

다른 팁

That's because some navigator need some time to load iframe in DOM

Here is the patch :

$('<iframe id="iframe1"></iframe>').appendTo($('.main')).ready(function() {
    setTimeout(function() {
$('#iframe1').contents().find('body').append('<h1 style="text-align: center;">This IS an iframe</h1>');
    }, 50);
});

Based on this answer : appending content into a dymanically created iframe gets an empty iframe

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top