PostMessage ONMessgae dispaly query

Hi all ,

as to communicate with the HTML i tried using the postmessage and onmessgae function .
but since very little knowledge of HTML i am not able to do it .

I was testing it like HTML code

console.log("*****************"); var myFunction = function(king){ document.body.innerHTML = king; }
window.onmessage = function(event){  
     console.log("--------------"); 
	 myfunction(event); 
	   }; 
   </script> 
console.log("###############"); 
</body> 
----------------------------------

I want to display a value in html t box which is thrown by wix command
as below :- WIX CODE

$w.onReady(function () {
});
export function button1_click(event) {
console.log(“butb1”);
$w(“#html1”).postMessage(“hello world”);
//Add your code for this event here:
}

please help me in clarifying the above and finding the error . as then i will try sending a data array to google chart as to populate the data table and display. the above would be a basic to understand the working

Your code looks legit. The problem I see with it is with the myfunction call. It is declared as myFunction but called as myfunction . Note that Javascript is case sensitive.

A way to discover such a problem is by opening chrome developer tools and adding the debugger keyword at the start of the function.

e.g.

<html>
    <body >
	console.log("*****************");
	<script>
            var myFunction = function(king){
                document.body.innerHTML = king;
            }
            window.onmessage = function(event){ 
                debugger;
	        console.log("--------------");
		myfunction(event);  // here is the problem
	    };
        </script>
        console.log("###############");
   </body>
</html>

Using debugger, you can step the code one line at a time and find which like breaks.

Ohh sorry for such a dumb question , i should have tried debugging it before posting it .

Thanks a lot for the answer and for the method to find the code break.

cheers :slight_smile: