onMessage( )

Adds an event handler that runs when the HTML Component sends a message.

The onMessage() function allows your page code to receive messages from an HTML Component on your page. When a message is received, the specified event handler is executed and the message can be retrieved using event.data.

To send a message from your HTML Component, use the postMessage() function in the HTML component's code. Generally, you call postMessage() from within a function:


When posting a message from within your HTML Component, you should specify your site's URL as the targetOrigin. If you use "*" instead, your message can be intercepted by a malicious site. To learn more, see Window.postMessage().

For more information on sending and receiving messages between your page and your HTML Component, see Working with the HTML Component in Wix Code.

Method Declaration
This method does not take any parameters
Return Type:HtmlComponent
Was this helpful?