Skip to content

PostWebMessageAsString - cWebView2Browser

Posts a message to the document loaded inside the WebView2 control

Type: Procedure

Parameters

Parameter Type Description
sMessage String String message to be posted

Syntax

Procedure PostWebMessageAsString String sMessage

Call Example

Send PostWebMessageAsString sMessage

Description

Posts a message to the document loaded inside the WebView2 control.

This message can be handled using JavaScript.

Sample

The example below shows how this 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;
});
</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 PostWebMessageAsString of oWebView2Browser "Hello world!"        
    End_Procedure
End_Object