There is a website, in it, in the pop-up, iframe is loaded from another domain, you need to catch the event happening in the iframe and process it already in the site. Please pick some solution (postmessage or something else is not important)

  • Same-origin policy will not allow. - Sergey Gornostaev

1 answer 1

It’s impossible to catch it yourself, firstly you don’t have access there for security reasons, the cross-domain is very limited. The only existing opportunity is to communicate via native postMessage

To do this, you will need from the beginning to add the necessary data to the iframe itself.

  parent.postMessage({array:[1,2]},"*"); // `*` или ваш домен 

And in the main frame will add the processor of this data.

 var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; var eventer = window[eventMethod]; var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; // Ждём сообщений от внутреннего фрейма... eventer(messageEvent,function(e) { console.log(e.data); //Object {array: Array[2]} },false); 

in this case, something else as you can talk cross-domain.

taken from David Walsh