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.

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

1 Answer 1

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .