6

I'm following the instructions on https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html to send a message from an iframed VF page to a Lightning component. The problem is I'm getting a DOMException in the console when postMessage is firing.

I tried simplifying the code even more to make sure I didn't have any issues with hard-coded domains.

Here's the Javascript function on my VF Page:

function sendToLC() {
    window.parent.PostMessage("Saved");
}

And here's the function in my Lightning Component controller:

doInit : function(component) {
    window.addEventListener("message", function(event) {
        console.log(event.data);
}, false);

When sendToLC is fired, I get:

LightningDemoRTCHange?id=aAr2F0000008at4SAA:13 Uncaught DOMException: Blocked a frame with origin "https://xxx--daniel--c.cs91.visual.force.com" from accessing a cross-origin frame.

I found Communicating between Lightning component and VF Page, but I don't have development mode on for my user.

  • 2
    while posting the message, please update the second parameter as "*" and method name is postMessage not PostMessage (just heads up) – Kiran Machhewar Jun 26 '18 at 17:23
  • @KiranMachhewar your comment is the answer. Want to post it as an answer and I can accept it? – Daniel Hoechst Jun 26 '18 at 18:36
  • @DanielHoechst Added the answer, hoping it should help someone facing same error. – Kiran Machhewar Jun 26 '18 at 18:45
5

Please change the method name to postMessage and postMessage has a second parameter which you need to use. You can use wildcard or put the specific domain (later is better)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.