Do something when iframe content does window.close

2.1k Views Asked by At

How can I catch that event?

This is my situation:

I have a html page that has a button. When i click the button, a popup shows up. Inside that popup there's an iframe with a different src from my domain.

That iframe contains a page that closes the window when its clicked. But when I click that from my own popup, it doesn't dissapear.

Can I catch this event window.close?

Thanks!

1

There are 1 best solutions below

0
David Bradshaw On

The iFrame will need to send a message to the page that contains it, saying that it wishes to close the window. You need to use the JavaScript PostMessage API to do this.

This approach requires you write code in both domains. If you are unable to do this, then your only option is to not use an iFrame and instead load the other domain directly into the popup.