我們使用simplemodal jquery插件來託管一個iframe作爲對話框的內容。關閉對話框後,simplemodal從文檔中刪除對話內容(包裝在div中的iframe),然後將其添加回文檔。如何防止Iframe在添加到文檔時重新加載?
下面的標記顯示了問題,同時從等式中取出簡單的模式。我只在這篇文章中提到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>
不幸的是,這仍然導致iframe重新加載。我們被綁定到iframe,直到我們能夠經歷更大的努力。我們正在與一個長期運行的代碼庫合作。 (還是)感謝你的建議。 – jrotello 2011-03-25 17:46:53