Argument | Description | Types / Required |
message | The message to post. | string
required |
webViewId | If specified, the message is posted to the web view with this ID. | number
not required |
targetOrigin | The target origin used by WebView.postWebMessage on Android. | string
not required |
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.
The action returns undefined.
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.
<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>