附加内容到dymanically创建的iframe得到一个空的iframe [英] appending content into a dymanically created iframe gets an empty iframe

查看:186
本文介绍了附加内容到dymanically创建的iframe得到一个空的iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery的片段如下:

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);
          });
          .....
        });
     });

在该事件被触发的第一次,只有一个IFRAME显示为空,但如果该事件被触发的第二次,内容被附加到iframe的成功,任何明显的错误在这个片段?提前致谢。

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? thanks in advance.

推荐答案

我相信某些浏览器需要一个短暂的延时才能识别新的iframe的DOM。使用超时应该工作:

I believe some browsers need a short delay for it to recognize the DOM of a new iframe. Using a timeout should work:

$('<iframe id="myFrame" name="myFrame">').appendTo("body").ready(function(){
    setTimeout(function(){
        $('#myFrame').contents().find('body').append(myContent);
    },50);
});

这篇关于附加内容到dymanically创建的iframe得到一个空的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆