CoreWebView2.PostWebMessageAsJson(String) Method

Definition

Posts the specified webMessageAsJson to the top level document in this WebView.

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 top level document in this WebView.

Examples

Runs the message event of the window.chrome.webview of the top-level document. 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 HTML document in the WebView to the host, navigate to WebMessageReceived. The message is sent asynchronously. If a navigation occurs before the message is posted to the page, the message is not be sent.

Applies to

See also