postMessage( )

Sends a message to the HTML Component.

The postMessage() function sends a message from your page code to the HTML Component.

To receive the message sent from the postMessage() function in your HTML Component, create an event handler for the window.onmessage event in the component's code. You create the event handler within an HTML `` tag. You get the received data by getting the data property of the event handler's event parameter.

Often, you define the window.onMessage event handler in a function that gets called when the HTML component loads using the body onload or window.onload:


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


  • An HTML Component needs to load before you can send it messages using the postMessage() function.

  • Usually an HTML Component finishes loading a short time after the page it is on finishes loading. So if you call postMessage() inside the page’s onReady() event handler, the HTML Component might not be ready yet. To call postMessage() as soon as possible after a page loads, send a message from the HTML Component to the page code as when the HTML Component is loaded and then call postMessage() upon receipt of that message.

  • Also, an HTML Component can send messages to the page it is on before the HTML Component itself has loaded completely. For example, this can happen if the HTML Component’s body, or one of its downloaded images, is large. To make sure the HTML component is loaded, send messages only after listening for an onLoad event in the HTML component.

Method Declaration
Method Parameters

The message to send to the HTML Component.

Was this helpful?