When the parent page and the iframe child page are cross-origin, directly calling functions will cause cross-origin errors. You need to use postMessage
to pass messages.
Parent page code:
postMessage
takes two parameters:
The first parameter is any data type, usually an object that encapsulates business data.
The second parameter is the target origin. By default, it is "/", but using "*"
allows cross-origin calls.
You can get the passed data via event.data
.
iframe child page code:
The parameters are defined the same way as the parent page calling the iframe child page.
đĄ If you enjoy my content and find it helpful,
feel free to support me â every donation means a lot!