@yael-luria Still did not understand the problem if i am honest ![]()
Tested this one successfuly…
$w.onReady(function() {console.log("READY");
$w("#html1").onMessage((event) => {
console.log(`Message received by page code: ${event.data}`);
});
$w("#button1").onClick((event)=>{
$w("#html1").postMessage("Message from page code!");
});
});
<html>
<head>
<script>
function init () {
// when a message is received from the page code
window.onmessage = (event) => {console.log(event)
if (event.data) {
console.log("HTML Code Element received a message!");
insertMessage(event.data);
alert(event.data);
}
}
// display received message
function insertMessage(msg) {
document.getElementById('demo').innerHTML = msg;
}
}
window.parent.postMessage('message from iframe', '*');
</script>
</head>
<body onload="init();" style="background-color:grey;">
<p id="demo">Message will go here</p>
</body>
</html>
Everything works like expected.