0 points

How to remove iframe within itself by using javascript


dashboard

Tue May 12 2020 11:23:22 GMT+0000 (UTC)

Posted by @mishka #javascript

//Replace the closeSelf() function in iframe page to the following

function closeSelf() {
   parent.window.postMessage("removetheiframe", "*");
}

//and on the parent page, add the following code to listen when the iframe sends a message :

function receiveMessage(event){
   if (event.data=="removetheiframe"){
      var element = document.getElementById('iframe-element');
      element.parentNode.removeChild(element);
   }
}
window.addEventListener("message", receiveMessage, false);
content_copy Copy

https://stackoverflow.com/questions/21881901/how-do-i-remove-iframe-within-itself-by-using-javascript