• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • System Namespace
      • UI Namespace
        • UI Action Invoker Namespace
        • UI.alert Action
        • UI.closeDialog Action
        • UI.enumerateWebViews Action
        • UI.getDisplayOptions Action
        • UI.getInputData Action
        • UI.getMaxDisplayDimensions Action
        • UI.postWebMessage Action
        • UI.setDisplayOptions Action
        • UI.showDialog Action
        • UI.view Action
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

UI.postWebMessage Action

Format
CS.UI.postWebMessage(message := ...ʃ, webViewId := ...ʅʃ, targetOrigin := ...ʅ)
ArgumentDescriptionTypes / Required
messageThe message to post.string
required
webViewIdIf specified, the message is posted to the web view with this ID.number
not required
targetOriginThe target origin used by WebView.postWebMessage on Android.string
not required
Description
The UI.postWebMessage action posts a message to a web view. The message must be specified as a string.
By default, this message is posted to the topmost web view, but the target web view can be specified by providing a webViewId. This web view ID, a unique number that uniquely identifies web views that CSPro displays, can be determined using the UI.enumerateWebViews action.
To listen for web messages in a cross-platform way, read about how to use the CSProActionInvoker.getWindowForEventListener method.
Return Value
The action returns undefined.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, if no web view is showing, or if webViewId is not associated with a web view currently showing.
Example (HTML + JavaScript)
<script>
    const CS = new CSProActionInvoker();

    // there should be at least two web views since the question text is showing
    const webViews = CS.UI.enumerateWebViews();

    console.assert(webViews.webViews.length >= 2 && webViews.webViewId == webViews.webViews[0].webViewId);

    // post a web message to the question text, which will be the last web view in the array
    CS.UI.postWebMessage({
        message: `Posting a message to the question text window at ${new Date().toISOString()}.`,
        webViewId: webViews.webViews[webViews.webViews.length - 1].webViewId
    });
</script>
See also: UI Action Invoker Namespace, UI.enumerateWebViews Action