I have two visualforce page lightning components on a lightning page.
I am unable to get them to communicate, there are no logs to the console and no errors to report. The posted messages are not received by the components on the page.
BUT when I use inspect to place an event listener and console log on the top level, I see the message logged, and when I do postmessage from the context of the receiving vfFrame, messages are console logged from the original (receiving visualforce page) event listener.
Sending Visualforce Component:
<button onClick="parent.postMessage('Sent Message', 'https://myOrg--myBox--c.visualforce.com')">Send</button>
On the receiving Visualforce Page:
<script>
var sfOrigin = "https://myOrg--myBox.lightning.force.com";
window.addEventListener("message", function(event) {
console.log(event);
console.log(event.origin);
if (event.origin !== sfOrigin) {
// Not the expected origin: reject message!
return;
}
// Handle message
console.log('received: ' + event.data);
}, false);
</script>
I have tried the following postMessage and event listener combinations:
<button onClick="parent.postMessage('Sent Message', 'https://myOrg--myBox--c.visualforce.com')">Send</button>
<button onClick="parent.postMessage('Sent Message', 'https://myOrg--myBox.lightning.force.com')">Send</button>
<button onClick="parent.postMessage('Sent Message', '*')">Send</button>
window.addEventListener("message", function(event) {
parent.addEventListener("message", function(event) {
window.parent.addEventListener("message", function(event) {
I have already referenced:
Communication between Lightning Component and Visualforce - DOMException