has.createWebViewContext(): WebViewContext
Creates a WebViewContext object, which is used to send messages to the web-view component.
Since: 2.0.4
Returns:
WebViewContext object.
Example:
const webViewContext = has.createWebViewContext();
WebViewContext.postMessage(Object object)
Sends a message to the web-view component.
Since: 2.0.4
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| data | string | object | Yes | Message to be sent to the web page. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
const webViewContext = has.createWebViewContext();
webViewContext.postMessage({
data: 'msg to H5',
success: () => {
console.info('postMessage success');
},
fail: (err) => {
console.error('postMessage fail', err);
},
complete: (res) => {
console.info('postMessage complete', res);
}
});