[英]Closing the iframe from javascript properly and by not hiding the iframe
我想關閉一個iframe ...並且我使用了類似的代碼,例如當我單擊關閉btn時使iframe可見為false或顯示為無...但是由於iframe沒有關閉,這正在影響我項目中的其他代碼而且我只是隱藏...而且代碼可以在Mozilla和Chrome中正常工作,因此可以很好地隱藏iframe。 但是在IE中這根本不起作用...所以我嘗試了其他一些其他方法,例如...在ifame頁面中,在關閉btn時調用此功能,請點擊:
function closeiframecommt() {
parent.closeiframefriends();
}
在包含iframe的頁面中,我將代碼編寫為:
function closeiframefriends()
{
var friends = document.getElementById("IFriends");
friends.style.display = "none";
}
所以...這在Mozilla和Chrome中工作正常,但在IE中...第一次關閉iframe時它會關閉,但是下次我嘗試打開iframe時會出現錯誤,而iframe不會僅打開...但是此顯示沒有或可見的錯誤正在影響項目中的其他代碼,因此我嘗試使用removechild代碼再次關閉iframe IE問題...所以您能以正確的代碼幫助我關閉iframe ...當我嘗試查找代碼時(如單擊Esc或在iframe之外的任何地方,它(iframe)都能正確關閉,所以我想知道..當我們按Esc或單擊iframe之外時,iframe會完美關閉而不影響其他代碼時會發生什么。
預先感謝您!
您不會“關閉” iframe,而是將其隱藏或刪除。 因為隱藏它不是您的選擇-您應將其刪除。 這適用於chrome和IE。
<!DOCTYPE html>
<head>
<title>test</title>
<style type="text/css">
.top {
height:100px;
width:200px;
background-color:green;
}
</style>
<script type="text/javascript">
function removeIFrame() {
var frame = document.getElementById("target");
frame.parentNode.removeChild(frame);
}
</script>
</head>
<body>
<div class="top" onclick="removeIFrame();"></div>
<iframe id="target" src="http://www.disney.com" width="100" height="100"></iframe>
<div class="top"></div>
</body>
頂部綠色div的onclick會處理從DOM中刪除iframe的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.