Web & React: <iframe>
Use the MessageChannel API to create a new channel. You’ll use the two ports connected to the channel to communicate between your application and the Embed Component inside the iframe.
const channel = new MessageChannel();
Send port2
into the iframe embedding the Component using the onLoad
callback of the <iframe>
element:
iframe.addEventHandler(“load”, (event) => {
event.target.contentWindow.postMessage("", "*", [channel.port2]);
});
Now that the Component has received port2
, listen to events from the iframe on port1
, the port you retained earlier:
channel.port1.onmessage = (event) => {
// check event.data.handlerName and event.data.eventType,
// and handle messages sent from the Everee embedded UX
};
The event's data
property will be a JavaScript object. See Component Events for details of the data structure.
Updated 24 days ago