Skip to main content

postWindowMessage()

Appsmith provides a way to enable safe cross-origin communication between different Window objects such as application or parent window and iframes using the postWindowMessage() function.

postWindowMessage() is used to send messages between parent apps or windows and child iframes.

Signature

postWindowMessage(message, targetIframe, targetOrigin)

Parameters

message

The message to send to the target iframe or window. Most JavaScript values are acceptable here, except null and undefined. This is an empty string ("") by default.

targetIframe

A string that sets where to send the message. If its value is "window", the message is sent to the parent application’s window (where Appsmith is embedded). To send a message to an iframe embedded within Appsmith, the string should be the name of the Iframe widget. This parameter is "window" by default.

targetOrigin

A string that is the URL or domain where messages are allowed to be sent. A value of "*" allows sending to any URL. To limit sending messages to only the parent application where Appsmith is embedded, enter the URL of the parent application. By default, this parameter is "*".

To see examples of postWindowMessage(), take a look at the sample app.

See also