繁体   English   中英

如何从iframe将元素追加到父体?

[英]How to append element to parent body from an iframe?

我在iframe中有这个代码。

<script type="text/javascript">
    $(document).ready(function(){
        $("body").append($("#ctap").html());
    });
</script>

我想将#ctap的html附加到父体。 我怎样才能做到这一点 ?

尝试使用document.ready中的一段代码

parent.$("body").append($("#ctap").html());

如果父体你应该有这样的东西:

var iFrame = $('#iframe_id');
var iContent = iFrame.contents().find("#ctap").html();
$("body").append( iContent );

为了能够从iframe访问主机页面的内容,由于跨域脚本限制,它们必须具有完全相同的位置(主机名和端口)。

请参阅如何使用iframe中的函数从父页面中删除iframe?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM