How to close an iframe within iframe itself with JavaScript?

Sometimes, we want to close an iframe within iframe itself with JavaScript.

In this article, we’ll look at how to close an iframe within iframe itself with JavaScript.

How to close an iframe within iframe itself with JavaScript?

To close an iframe within iframe itself with JavaScript, we use the remove the iframe.

For instance, we get the parent of the iframe and then call closeFrame on it by writing

parent.closeIFrame();

where closeIFrame is

function closeIFrame() {
  document.getElementById("youriframeid").remove();
}

in the parent.

We select the iframe with getElementById.

And then we call remove to remove it.

Conclusion

To close an iframe within iframe itself with JavaScript, we use the remove the iframe.