The OpenD Programming Language

ICoreWebView2.PostWebMessageAsJson

Post the specified webMessage to the top level document in this WebView. The main page receives the message by subscribing to the message event of the window.chrome.webview of the page document.

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

The event args is an instance of MessageEvent. The ICoreWebView2Settings::IsWebMessageEnabled setting must be TRUE or the web message will not be sent. The data property of the event arg is the webMessage string parameter parsed as a JSON string into a JavaScript object. The 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 add_WebMessageReceived. The message is delivered asynchronously. If a navigation occurs before the message is posted to the page, the message is discarded.

\snippet ScenarioWebMessage.cpp WebMessageReceived

interface ICoreWebView2
HRESULT
PostWebMessageAsJson
(
in LPCWSTR webMessageAsJson
)

Meta