1

We have an iframe in a domain different from our main website.

This iframe consists of a form where we want to track some events from outside.

There are many web resources (MDN, Matt West's Blog...) teaching how to send a postMessage for a window, but the path is always sending a message from the parent to the iframe/popup.

If the parent is at the same domain, it is possible to send the message as well, as pointed by David Walsh.

We need to send a message from the iframe to the parent.

Also, they are in different domains.

Is that possible?

Thanks

Thiago Melo
  • 1,157
  • 1
  • 14
  • 31

1 Answers1

1

Did you try it?

parent.postMessage(message,'*') works just fine across different domains, in all modern browsers.

The receiver's message handler should check the origin to make sure it's the domain they're expecting.

geocar
  • 9,085
  • 1
  • 29
  • 37