[英]Removing iframe from page
我正在為提交表單動態創建一個iframe,提交后我需要從頁面中刪除iframe表單。我刪除了以下但是沒有刪除,
function remove(){
var frame = document.getElementById("upload_iframe"),
var frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.removeChild(frameDoc.documentElement);
}
如何完全刪除表格中的ifarme。
謝謝
Frame有2個行為:frame作為文檔元素(如div或其他DOM元素),frame作為window元素(如全局window
對象)。 因此,如果您想從DOM樹中刪除iframe,您必須使用iframe與DOM元素一樣
function remove(){
var frame = document.getElementById("upload_iframe");
frame.parentNode.removeChild(frame);
}
我一直在做的一種方式(因為我有大量的iframe)是使用jQuery,
$('iframe').remove()
或者只有一個iframe你可以使用它的ID刪除它,仍然使用jQuery
$('#iframeID').remove()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.