简体   繁体   中英

Removing iframe from page

I am creating an iframe dynamically for submmiting a form,after submitting i need to remove the iframe form the page.I removed itas follows but it is not removed,

function remove(){
 var frame = document.getElementById("upload_iframe"),
 var frameDoc = frame.contentDocument || frame.contentWindow.document;
 frameDoc.removeChild(frameDoc.documentElement);
}

How to remove the ifarme form the form completely.

Thanks

Frame has 2 behaviors: frame as document element (like div or another DOM element) and frame as window element (like global window object). So if you want to remove iframe from DOM tree you have to work with iframe like with DOM element

function remove(){
 var frame = document.getElementById("upload_iframe");
 frame.parentNode.removeChild(frame);
}

A way I've been doing it (since I have a large amount of iframes) is using jQuery,

$('iframe').remove()

or in the case of only one iframe you can remove it using its ID, still with jQuery

$('#iframeID').remove()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM