Removing iframe from page

I create an iframe dynamically to split the form, after submitting I need to remove the iframe form on the page. I deleted it, but it is not deleted,

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

How to remove ifarme completely form form.

thanks

+6
source share
2 answers

A frame has 2 types of behavior: a frame as a document element (for example, a div or another DOM element) and a frame as a window element (for example, a global window object). Therefore, if you want to remove the iframe from the DOM tree, you need to work with the iframe as a DOM element

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

How I did it (since I have a lot of iframes) jQuery is used,

 $('iframe').remove() 

or in case of only one iframe, you can delete it using your ID, still with jQuery

 $('#iframeID').remove() 
+1
source

Source: https://habr.com/ru/post/925386/


All Articles