CoreWebView2Frame.PostWebMessageAsJson(String) Method

Definition

Posts the specified webMessageAsJson to the current frame.

public void PostWebMessageAsJson (string webMessageAsJson);
member this.PostWebMessageAsJson : string -> unit
Public Sub PostWebMessageAsJson (webMessageAsJson As String)

Parameters

webMessageAsJson
String

The web message to be posted to the iframe.

Examples

Runs the message event of the window.chrome.webview of the iframe. JavaScript in that document may subscribe and unsubscribe to the event using the following code:

window.chrome.webview.addEventListener('message', handler)
window.chrome.webview.removeEventListener('message', handler)

Remarks

The event args is an instance of MessageEvent. The IsWebMessageEnabled setting must be true or the message will not be sent. The event arg's data property of the event arg is the webMessageAsJson string parameter parsed as a JSON string into a JavaScript object. The event arg's source property of the event arg is a reference to the window.chrome.webview object. For information about sending messages from the iframe to the host, navigate to WebMessageReceived. The message is sent asynchronously. If a navigation occurs before the message is posted to the iframe, the message is not be sent.

Applies to

See also