Communication with parent page

I have embedded my playcanvas project inside an iframe and need to pass few parameters from parent page to the playcanvas project.
I have a button on my parent page.

Here is the code I am calling on the button click -
var msg = “170”;
console.log("sending message " + msg);
iframe.contentWindow.postMessage(JSON.stringify(msg), ‘’);

And I am using this code inside my playcanvas script -
window.addEventListener(‘message’, function (event) {
console.log(“message received”);
}, false);

I am getting the console of html parent page but on getting the console of playcanvas message listen event.

Got the issue resolved. We need to add /e in the iframe source url like ‘’.

1 Like