OnWebMessageReceived - cWebView2Browser
Sent when the page has sent a WebMessage to the host application
Type: Event
Parameters
| Parameter | Type | Description |
|---|---|---|
| sUrl | String | URL of the document sending the message |
| sMessageAsJson | String | String containing the JSON representation of the message |
| sMessageAsString | String | Message text |
Syntax
Procedure OnWebMessageReceived String sUrl String sMessageAsJson String sMessageAsString
Description
This message is sent when the page has sent a WebMessage to the host application.
If the message consists of a JavaScript object it will be serialized to JSON and the sMessageAsJson will contain it.
If the message is a string, then sMessageAsString will contain the message.
Sample
The example below shows how to send such a message from JavaScript.
Object oWebView2Browser is a cWebView2Browser
Set Size to 79 243
Set Location to 6 3
Procedure OnCreate
Send NavigateToString @'
<html>
<head>
<title>WebView Test Page</title>
</head>
<body>
<script>
function sendMessage(){
window.chrome.webview.postMessage("Hello DataFlex!");
}
</script>
<button onclick="sendMessage();">Message</button>
</body>
</html>'
End_Procedure
Procedure OnWebMessageReceived String sUrl String sMessageAsJson String sMessageAsString
Send Info_Box sMessageAsString sUrl
End_Procedure
End_Object