0

I have a html page where when a button is clicked it opens an iframe page.
In the iframe I made a button to close it, but it doesn't work.
iframe and page are all the same site!

let closeBtn = document.querySelector ("# close_btn"); // The "cross" button in the iframe
closeBtn.onclick = function () {

     write.classList.add ("write-off"); // Add the class to the main HTML page
     dimming.classList.add ("write-dimming-off"); // Add the class to the main HTML page
};

It doesn't work either.

let closeBtn = document.querySelector ("# close_btn");
closeBtn.onclick = function() {

    window.parent.document.querySelector(".write").classList.add("write-off");
    window.parent.document.querySelector(".write-dimming").classList.add("write-off");
};
Brendan8c
  • 369
  • 2
  • 11

1 Answers1

0

assign an id to your iframe, like <iframe id="Closed"...

Then you need a function to remove the iframe

<a href="javascript: window.parent.document.getElementById('Closed').parentNode.removeChild(window.parent.document.getElementById('Closed'))">Close</a>
  • It works yes! But I need, when clicking the "cross" in the iframe, add classes to the boxes on the main page. I want to do the following: 1) I need to click on a button on the home page. 2) Open the shape in the middle of the window, and darken the background. I think this is done via an iframe .. (pop up for site) – Brendan8c Mar 07 '21 at 18:44