// Configure message handler
$w.onReady(() => {
$w('#receivedMessages').text = "Messages Received:\n";
// when a message is received from the HTML Component
$w("#html1").onMessage( (event, $w) => {
addReceivedMessage(event.data);
} );
} );
// Update received message log
function addReceivedMessage(message) {
let newMessage = JSON.stringify(message);
$w('#receivedMessages').text += '\n'+newMessage;
}
// Send message to html component
function sendMessage(action, message, payload) {
if (action && message) {
let theMessage = {action:message};
if (payload) {
theMessage.payload = payload;
}
$w('#html1').postMessage(theMessage);
}
}
// Request OS Type from html component
export function button1_click(event, $w) {
// Ask html component for OS
sendMessage('action', 'OSInfo');
}
HTML Component Code