【问题标题】:How to copy content of iframe into popup window?如何将 iframe 的内容复制到弹出窗口中?
【发布时间】:2011-07-26 08:09:23
【问题描述】:

有没有办法将 iframe 的内容复制到 jQuery 的弹出窗口中?

$(popUpWindow.document).append($('#iframe1').contents());
$(popUpWindow.document).append($('#iframe1').contents().find('body').html()); 

它们都不起作用!

谢谢

【问题讨论】:

  • iFrame 是否指向同一域中的页面?您可能会遇到跨域安全问题。另外,如果你要访问整个页面,popup.location = iframe.location 有什么问题?
  • @Bard ...事实上,iFrame 并没有指向任何外部页面,它只是一个隐藏的 iFrame,我们通常在其中存储一个 html 页面。
  • 您可能会在 copying the dom to a new window 上找到此答案有帮助。
  • @Nicholas ...事实上,我的麻烦是从 iFrame 获取内容
  • 将 html 内容放在隐藏的
    中而不是 iframe 中可能更容易。

标签: javascript jquery jquery-selectors javascript-framework


【解决方案1】:

如果你需要做的只是获取 iframe 内容,你可以尝试比 jquery 更底层的东西:raw javascript!

var getIframeContent = function (id) {
    var iframe = document.getElementById(id);
    return iframe.contentWindow.document.body.innerHTML;
}

但我想在 JQuery 的底层也会发生类似的事情。

【讨论】:

    【解决方案2】:

    请说明您使用的是哪个弹出窗口以及内容是什么意思。

    jquery-ui 弹出(对话框)示例

    HTML:

    <div id="myDialog" >
      <p>default dialog</p>
    </div>
    

    jQuery:

    $(function() {
        $( "#myDialog" ).dialog();
        $( "#myDialog p" ).html($("iframe").contents().find("body").html());
    }); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多