【发布时间】:2012-01-09 05:39:14
【问题描述】:
看看这个简单的 HTML:
<div id="wrap1">
<iframe id="iframe1"></iframe>
</div>
<div id="warp2">
<iframe id="iframe2"></iframe>
</div>
假设我想移动换行符,使#wrap2 位于#wrap1 之前。 iframe 被 JavaScript 污染了。我知道 jQuery 的 .insertAfter() 和 .insertBefore()。但是,当我使用这些时,iFrame 会丢失其所有 HTML、JavaScript 变量和事件。
假设以下是 iFrame 的 HTML:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// The variable below would change on click
// This represents changes on variables after the code is loaded
// These changes should remain after the iFrame is moved
variableThatChanges = false;
$(function(){
$("body").click(function(){
variableThatChanges = true;
});
});
</script>
</head>
<body>
<div id='anything'>Illustrative Example</div>
</body>
</html>
在上面的代码中,如果用户点击正文,变量variableThatChanges 会...改变。此变量和点击事件应在 iFrame 移动后保留(以及已启动的任何其他变量/事件)
我的问题如下:使用 JavaScript(使用或不使用 jQuery),如何移动 DOM(及其 iframe 子级)中的包装节点,以使 iFrame 的窗口保持不变,以及 iFrame 的事件/variables/etc 保持不变?
【问题讨论】:
-
Mozilla 提出的当前错误 ...bugzilla.mozilla.org/show_bug.cgi?id=254144
-
@ManseUK:其他问题并没有真正帮助......但这个错误很有趣。
-
@SalmanA 如何让父母“围绕”孩子?
-
@denodster 当我打开这个问题时,想要的效果是改变元素列表的顺序,每个元素都带有
inline-block显示......在这一点上,我猜一个通用的考虑到他人的利益,解决方案(或实际上是不可能的声明)将是最合适的。
标签: javascript jquery dom iframe