移动元素,以iframe的父数据和事件 [英] Move elements to iframe's parent with data and events

查看:112
本文介绍了移动元素,以iframe的父数据和事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这种情况。
我有一个用户可以在提交前执行几项操作一个iframe中一个复杂的UI。在这个过程中,用户可以切换到另一页(在iframe)回来。这意味着iframe内2回传。

this is the situation. I have a complex UI inside an iframe in which a user can perform several actions before submitting. During the process, the user can switch to another page (in the iframe) and come back. That means 2 postbacks inside the iframe.

显然,我不希望用户失去了一切,但因为所有的行动都是在客户端完成,我不能从服务器重新加载$ ​​P $ pvious状态。

Obviously, I don't want the user to lose everything but since all the actions have been done on the client-side, I can't reload the previous state from the server.

所以,现在,我想移动的第一页内容的iframe父,并把它放回原处,当我们回来。我半路上有自元素显示在后面的页面,但他们失去了他们的数据属性和事件处理程序。

So now, I'm trying to move the first page content to the iframe parent and put it back in place when we come back. I'm half way there since the elements show back in the page but they lose their data attributes and event handlers.

我使用这个移动父内容:

I'm using this to move the content on the parent :

$("#resp").clone(true).attr("id", "refillResp").appendTo(window.top.$("#global"));

这把它放回去:

window.top.$("#global").find("#refillResp").clone(true).attr("id", "resp").appendTo($("#tdResp"));

有没有谁知道一个办法做到这一点?
PS:我测试过的内容如何反应过来的时候简单地移动了家长和数据和事件都已经走了。

Is there anyone who knows a way to do this ? PS: I've tested how the content react when simply moved on the parent and data and events are already gone.

推荐答案

这更是一个评论,但它并不适合在那里。

It is more a comment, but it does not fit in there.

各地不同的文档移动DOM元素周围常是有点冒险。因为它可能会导致意外的行为(内存泄漏,其行为元素怪)。在当前的浏览器它的大部分时间工作,但我不会推荐它。

Moving DOM element around different documents around is alway a little bit risky. Because it could lead to unexpected behavior (memory leaks, elements that behave strange). In current browsers it most of the time works, but i would not recommend it.

如果您使用jQuery你有另一个问题。 jQuery有用于存储信息有关数据事件分配给一个对象,这个缓存存储与高速缓存文档窗口。欲知详情,请阅读这个答案,另一个问题:

If you use jQuery you have another problem. jQuery has a cache for storing informations about data and event that are assigned to an Object, this cache is stored with the documents window. For further details please read this answer, to another question:

<一个href=\"http://stackoverflow.com/questions/16689280/how-to-set-jquery-data-on-an-iframe-body-tag-and-retrieve-it-from-inside-the-i/16690904#16690904\">How设置jQuery的数据()的iframe body标签,并从iFrame中找回?

所以,如果你使用jQuery不同的文档之间移动元素,你将目前,一方面松动这些信息,在另一方面,它可能会导致内存泄漏。

So if you move element with jQuery between different document, you will currently on the one hand loose these informations, on the other hand it could result in memory leaks.

随着事件则更加复杂。例如如果你委托的事件它可以成为完全乱了。

With events it is even more complicate. e.g. if you have delegated events it could be become completely messy.

如果您需要iframe和家长之间交换数据,你应该想一些其他的逻辑。

If you need to exchange data between iframe and parent you should think of some other logic.

我也给我的对方的回答,在那里我提到了这个信息的评论中提到这一点:
<一href=\"http://stackoverflow.com/questions/15884994/javascript-can-data-be-passed-bi-directionally-through-an-iframe/\">How设置jQuery的数据()的iframe body标签,并从iFrame中找回?

I also mention this in a comment to the other answer of me, where i referred to this post: How to set jQuery data() on an iFrame body tag and retrieve it from inside the iFrame?

这篇关于移动元素,以iframe的父数据和事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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