In order to communicate between an LWC and a Visualforce iFrame I intend to use postMessage
.
For example, in VF I might have:
// Function to send a message to the LWC
const sendEventToLWC = function(actionName, details) {
if ( parent )
{
parent.postMessage(
JSON.stringify({ action: actionName, details: details }),
lightningOrigin
);
}
}
// Listener to respond to post messages from the LWC
window.addEventListener('message', function (event) {
if (event.origin === lightningOrigin) {
// Perform the requested action
}
});
In the LWC I would have very similar code, referencing visualforceOrigin
instead of lightningOrigin
The questions are:
- How do I programatically work out the visualforceOrigin when in the LWC (or Apex) context?
- How do I programatically work out the lightningOrigin when in the Visualforce (or Apex) context?