简体   繁体   English

如何沿着DOM移动iframe而不丢失它的内容?

[英]How to move iframe along the DOM without losing it's content?

Is it possible? 可能吗?

I have tried to move it, but iframe contents dissapear. 我试图移动它,但iframe内容消失了。

Tried to get contents of iframe and place them in the new place but all handlers ofc dissapear. 试图获取iframe的内容并将它们放在新的位置,但所有处理程序都消失了。

Tried to do the same, but with new jQuery 1.4.2 feature, that clones all events along with it. 尝试做同样的事情,但使用新的jQuery 1.4.2功能,可以克隆所有事件。

But it doesn't work :) 但它不起作用:)

So I have decided to ask here for help. 所以我决定在这里寻求帮助。

How to move the damn iframe to another place in the document without losing it's contents? 如何将该死的iframe移动到文档中的另一个位置而不会丢失它的内容? ^_^ ^ _ ^

Thanks 谢谢

Added: 添加:

txtad_iframe = ad_container.find('iframe');                 
its_contents = txtad_iframe.contents();
its_body = its_contents.find("div:first").clone(true).insertAfter(cthis.find('#photos'));

Here i'm trying to copy contents to new ad container. 在这里,我正在尝试将内容复制到新的广告容器中。 But it doesn't work. 但它不起作用。 Context banner doesn't react on click event. 上下文横幅不会对点击事件做出反应。

I have tried to move ad_container to container, but iframe body content dissapears. 我试图将ad_container移动到容器,但是iframe正文内容消失了。

I believe that items in an iframe aren't bound unless done so explicitly in that iframe. 我认为iframe中的项目不受约束,除非在iframe中明确地这样做。 in other words, the iframe contents don't inherit the binding events from the parent window. 换句话说,iframe内容不会从父窗口继承绑定事件。 you will have to bind first in the iframe and then move stuff around. 你必须先在iframe中绑定然后移动东西。

i think. 我认为。

EDIT 编辑

I think you may want to do something like 我想你可能想做点什么

its_body = its_contents.find("div:first").clone(true);
$(its_body).insertAfter(cthis.find('#photos'));

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

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