【发布时间】:2011-03-22 19:33:19
【问题描述】:
我们使用 simplemodal jquery 插件来托管 iframe 作为对话框的内容。关闭对话框后,simplemodal 会从文档中删除对话框内容(包含在 div 中的 iframe),然后将其添加回文档中。
以下标记演示了将 simplemodal 排除在等式之外的问题。我在这篇文章中只提到 simplemodal 是为了说明为什么要删除和重新添加 iframe。
如何防止 iframe 在重新添加到文档时重新加载其内容?
任何帮助将不胜感激!
test.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
iframe{ padding: 0px; margin: 0px; width: 300; height: 300; }
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#go").click(function() {
var frame = $("#myframe");
frame.remove();
frame.prependTo("body");
});
});
</script>
</head>
<body>
<iframe name="myframe" id="myframe" src="test2.html"></iframe>
<div>
<button id="go">GO</button>
</div>
</body>
</html>
test2.html
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert("this should not get called when the iframe is re-added to the document");
});
</script>
</head>
<body>
This is iframe content.
</body>
</html>
【问题讨论】:
标签: javascript jquery dom simplemodal