Removing iframe from page

前端 未结 2 1516
栀梦
栀梦 2020-12-18 00:08

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,

         


        
相关标签:
2条回答
  • 2020-12-18 00:41

    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);
    }
    
    0 讨论(0)
  • 2020-12-18 00:43

    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()
    
    0 讨论(0)
提交回复
热议问题