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.
handler(event: HtmlComponentMessageEvent): void
The name of the function or
the function expression to run when the HTML Component sends a message.