postMessage( )


Sends a message to a page's parent.

If a page is embedded within another site, using an HtmlComponent on a Wix site or an iframe on a non-Wix site, call this method to send a message from the inner site to the outer site.

When the parent site is a Wix site, call onMessage() to receive the message on the parent page.

When the parent site is a non-Wix site, use the page's window.onMessage event handler to read the data property of the received MessageEvent to receive the message on the parent page.

Method Declaration
Copy
function postMessage(message: object, target: string): Promise<object>;
Method Parameters
messageMessageRequired

The message to send.


targetstring

The target to send the message to. Must be "parent" or omitted. Default: "parent".

Returns
Return Type:Promise<object>
JavaScript
/* * * * * * * * * * * * * * * * * * * * * * * * Code for the inner site to post a message * * * * * * * * * * * * * * * * * * * * * * * */ import wixWindowFrontend from "wix-window-frontend"; // ... wixWindowFrontend.postMessage(dataObj); /* * * * * * * * * * * * * * * * * * * * * * * * * * Code for the outer site to receive a message * * * * * * * * * * * * * * * * * * * * * * * * * * * * $w("#myHtmlComponent").onMessage( (event, $x) => { * let message = event.data; * } ); */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?