Notes
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Note
This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.
interface ICoreWebView2WebMessageReceivedEventArgs
: public IUnknown
Event args for the WebMessageReceived
event.
Summary
Members | Descriptions |
---|---|
get_Source | The URI of the document that sent this web message. |
get_WebMessageAsJson | The message posted from the WebView content to the host converted to a JSON string. |
TryGetWebMessageAsString | If the message posted from the WebView content to the host is a string type, this method returns the value of that string. |
Applies to
Product | Introduced |
---|---|
WebView2 Win32 | 0.9.430 |
WebView2 Win32 Prerelease | 0.9.488 |
Members
get_Source
The URI of the document that sent this web message.
public HRESULT get_Source(LPWSTR * source)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_WebMessageAsJson
The message posted from the WebView content to the host converted to a JSON string.
public HRESULT get_WebMessageAsJson(LPWSTR * webMessageAsJson)
Run this operation to communicate using JavaScript objects.
For example, the following postMessage
runs result in the following WebMessageAsJson
values.
postMessage({'a': 'b'}) L"{\"a\": \"b\"}"
postMessage(1.2) L"1.2"
postMessage('example') L"\"example\""
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
TryGetWebMessageAsString
If the message posted from the WebView content to the host is a string type, this method returns the value of that string.
public HRESULT TryGetWebMessageAsString(LPWSTR * webMessageAsString)
If the message posted is some other kind of JavaScript type this method fails with the following error.
E_INVALIDARG
Run this operation to communicate using simple strings.
For example, the following postMessage
runs result in the following WebMessageAsString
values.
postMessage({'a': 'b'}) E_INVALIDARG
postMessage(1.2) E_INVALIDARG
postMessage('example') L"example"
The caller must free the returned string with CoTaskMemFree
. See API Conventions.