PostWebMessageAsJson - cWebView2Browser
Posts a message to the document loaded inside the WebView2 control
Type: Procedure
Parameters
| Parameter | Type | Description |
|---|---|---|
| sJson | String | String containing JSON data |
Syntax
Procedure PostWebMessageAsJson String sJson
Call Example
Send PostWebMessageAsJson sJson
Description
Posts a message to the document loaded inside the WebView2 control.
This message can be handled using JavaScript. The event data in JavaScript will be the parsed JSON.
Sample
The example below shows how such a message can be handled in JavaScript:
Object oWebView2Browser is a cWebView2Browser
Set Size to 87 250
Set Location to 0 0
Set peAnchors to anAll
Procedure OnCreate
Forward Send OnCreate
Send NavigateToString @'
<!DOCTYPE html>
<html>
<body>
<div id="data"></div>
<script>
window.chrome.webview.addEventListener("message", oEv =>{
document.getElementById("data").textContent = oEv.data.message;
});
</script>
</body>
</html>'
End_Procedure
End_Object
Object oPostMsgBtn is a Button
Set Location to 91 5
Set Label to 'Post Msg'
// fires when the button is clicked
Procedure OnClick
Send PostWebMessageAsJson of oWebView2Browser @'{ "message": "Hello world!" }'
End_Procedure
End_Object