Implements a **WebviewController** to control the behavior of the **\<Web>** component. A **WebviewController** can control only one **\<Web>** component, and the APIs in the **WebviewController** can be invoked only after it has been bound to the target **\<Web>** component.
Implements a **WebviewController** to control the behavior of the **\<Web>** component. A **WebviewController** can control only one **\<Web>** component, and the APIs (except static APIs) in the **WebviewController** can be invoked only after it has been bound to the target **\<Web>** component.
### initializeWebEngine
static initializeWebEngine(): void
Loads the dynamic link library (DLL) file of the web engine. This API can be called before the **\<Web>** component is initialized to improve the startup performance.
| clearRom | boolean | Yes | Whether to clear the cache in the ROM and RAM at the same time. The value **false** means to only clear the cache in the RAM.|
| clearRom | boolean | Yes | Whether to clear the cache in the ROM and RAM at the same time. The value **true** means to clear the cache in the ROM and RAM at the same time, and **false** means to only clear the cache in the RAM.|
**Error codes**
...
...
@@ -2405,7 +2722,6 @@ For details about the error codes, see [Webview Error Codes](../errorcodes/error
Implements a **WebCookie** object to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookie** object.
Implements a **WebCookieManager** instance to manage behavior of cookies in **\<Web>** components. All **\<Web>** components in an application share a **WebCookieManager** instance.
### getCookie
...
...
@@ -3600,7 +3965,7 @@ Implements a **WebAsyncController** object, which can be used to control the beh
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.
| baseName | string | Yes| Save path. The value cannot be null. |
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise.|
**Example**
...
...
@@ -3677,14 +4042,14 @@ Stores this web page. This API uses a promise to return the result.
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.
| baseName | string | Yes| Save path. The value cannot be null. |
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory. |
| Promise\<string> | Promise used to return the save path if the operation is successful and null otherwise. |
**Example**
...
...
@@ -4100,6 +4465,15 @@ Provides the element information of the area being clicked. For details about th
| type | [HitTestTypeV9](#hittesttypev9) | Yes| No| Element type of the area being clicked.|
| extra | string | Yes| No|Extra information of the area being clicked. If the area being clicked is an image or a link, the extra information is the URL of the image or link.|
## WebMessage
Describes the data types supported for [WebMessagePort](#webmessageport).
| schemeName | string | Yes | Yes | Name of the custom URL scheme. The value can contain a maximum of 32 characters and include only lowercase letters, digits, periods (.), plus signs (+), and hyphens (-). |
| isSupportCORS | boolean | Yes | Yes | Whether to support cross-origin resource sharing (CORS). |
| isSupportFetch | boolean | Yes | Yes | Whether to support fetch requests. |
@@ -467,13 +467,13 @@ Sets whether to enable geolocation access. By default, this feature is enabled.
mediaPlayGestureAccess(access: boolean)
Sets whether a manual click is required for video playback.
Sets whether video playback must be started by user gestures. This API is not applicable to videos that do not have an audio track or whose audio track is muted.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
Sets whether to display the horizontal scrollbar, including the system default scrollbar and custom scrollbar. By default, the horizontal scrollbar is displayed.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
Sets whether to display the vertical scrollbar, including the system default scrollbar and custom scrollbar. By default, the vertical scrollbar is displayed.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| size | number | Yes | 13 | Default fixed font size of the web page. The value is a non-negative integer ranging from 1 to 72. If the value is less than 1, the value 1 is used. If the value is greater than 72, the value 72 is used.|
| size | number | Yes | 13 | Default fixed font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
**Example**
...
...
@@ -724,11 +827,11 @@ Sets the default fixed font size of the web page.
| size | number | Yes | 16 | Default font size of the web page. The value is a non-negative integer ranging from 1 to 72. If the value is less than 1, the value 1 is used. If the value is greater than 72, the value 72 is used.|
| size | number | Yes | 16 | Default font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
**Example**
...
...
@@ -755,11 +858,11 @@ Sets the default font size of the web page.
| size | number | Yes | 8 | Minimum font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
| size | number | Yes | 8 | Minimum font size of the web page. The value is a non-negative integer ranging from 1 to 72. If the value is less than 1, the value 1 is used. If the value is greater than 72, the value 72 is used.|
| size | number | Yes | 8 | Minimum logical font size to set, in px. The value ranges from -2^31 to 2^31-1. In actual rendering, values greater than 72 are handled as 72, and values less than 1 are handled as 1. |
**Example**
...
...
@@ -786,27 +920,28 @@ Sets the minimum font size of the web page.
| family | string | Yes | cursive | Cursive font family of the web page.|
| family | string | Yes | cursive | Cursive font family to set.|
**Example**
...
...
@@ -982,6 +1117,100 @@ Sets the cursive font family of the web page.
}
```
### darkMode<sup>9+</sup>
darkMode(mode: WebDarkMode)
Sets the web dark mode. By default, web dark mode is disabled. When it is enabled, the **\<Web>** component enables the dark theme defined for web pages if the theme has been defined in **prefer-color-scheme** of a media query, and remains unchanged otherwise. To enable the forcible dark mode, use this API with [forceDarkAccess](#forcedarkaccess9).
**Parameters**
| Name| Type| Mandatory| Default Value | Description |
Sets whether to enable forcible dark mode for the web page. By default, this feature is turned off. This API is applicable only when dark mode is enabled in [darkMode](#darkmode9).
**Parameters**
| Name| Type| Mandatory| Default Value | Description |
| geolocation | [JsGeolocation](#jsgeolocation) | The user's operation.|
| geolocation | [JsGeolocation](#jsgeolocation) | User operation.|
**Example**
...
...
@@ -2285,6 +2514,7 @@ Registers a callback for window creation.
```ts
// xxx.ets
importweb_webviewfrom'@ohos.web.webview'
@Entry
@Component
structWebComponent{
...
...
@@ -2626,7 +2856,7 @@ Notifies the **\<Web>** component of the user's confirm operation in the dialog
## FullScreenExitHandler<sup>9+</sup>
Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see onFullScreenEnter.
Implements a **FullScreenExitHandler** object for listening for exiting full screen mode. For the sample code, see [onFullScreenEnter](#onfullscreenenter9).
### exitFullScreen<sup>9+</sup>
...
...
@@ -2830,15 +3060,15 @@ Obtains the MIME type of the resource response.
### setResponseData<sup>9+</sup>
setResponseData(data: string)
setResponseData(data: string | number)
Sets the data in the resource response.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ---- | ------ | ---- | ---- | ----------- |
| data | string | Yes | - | Resource response data to set.|
| Name| Type | Mandatory| Default Value| Description |
| resources | Array\<string\> | Yes | - | List of accessible resources requested by the web page.|
| resources | Array\<string\> | Yes | - | List of resources that can be requested by the web page with the permission to grant.|
## ContextMenuSourceType<sup>9+</sup>
| Name | Description |
| -------------------- | ---------- |
| None | Other event sources. |
| Mouse | Mouse event. |
| LongPress | Long press event. |
## ContextMenuMediaType<sup>9+</sup>
| Name | Description |
| ------------ | ----------- |
| None | Non-special media or other media types.|
| Image | Image. |
## ContextMenuInputFieldType<sup>9+</sup>
| Name | Description |
| ------------ | ----------- |
| None | Non-input field. |
| PlainText | Plain text field, such as the text, search, or email field. |
| Password | Password field. |
| Number | Numeric field. |
| Telephone | Phone number field.|
| Other | Field of any other type. |
## ContextMenuEditStateFlags<sup>9+</sup>
| Name | Description |
| ------------ | ----------- |
| NONE | Editing is not allowed. |
| CAN_CUT | The cut operation is allowed. |
| CAN_COPY | The copy operation is allowed. |
| CAN_PASTE | The paste operation is allowed. |
| CAN_SELECT_ALL | The select all operation is allowed.|
## WebContextMenuParam<sup>9+</sup>
Provides the information about the context menu that is displayed when a page element is long pressed. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
Implements a context menu, which is displayed after the user clicks the right mouse button or long presses a specific element, such as an image or a link. For the sample code, see [onContextMenuShow](#oncontextmenushow9).
| retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. The **[GeolocationPermissions](#geolocationpermissions9)** API can be used to manage the geolocation permission status saved to the system.|
| retain | boolean | Yes | - | Whether the geolocation permission status can be saved to the system. You can manage the geolocation permissions saved to the system through [GeolocationPermissions<sup>9+</sup>](../apis/js-apis-webview.md#geolocationpermissions).|
## WebController
Implements a **WebController** to control the behavior of the **\<Web>** component. A **WebController** can control only one **\<Web>** component, and the APIs in the **WebController** can be invoked only after it has been bound to the target **\<Web>** component.
This API is deprecated since API version 9. You are advised to use [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller).
### Creating an Object
```
webController: WebController = new WebController()
```
### requestFocus
### requestFocus<sup>(deprecated)</sup>
requestFocus()
Requests focus for this web page.
This API is deprecated since API version 9. You are advised to use [requestFocus<sup>9+</sup>](../apis/js-apis-webview.md#requestfocus).
**Example**
```ts
...
...
@@ -3247,12 +3624,14 @@ Requests focus for this web page.
}
```
### accessBackward
### accessBackward<sup>(deprecated)</sup>
accessBackward(): boolean
Checks whether going to the previous page can be performed on the current page.
This API is deprecated since API version 9. You are advised to use [accessBackward<sup>9+</sup>](../apis/js-apis-webview.md#accessbackward).
**Return value**
| Type | Description |
...
...
@@ -3281,12 +3660,14 @@ Checks whether going to the previous page can be performed on the current page.
}
```
### accessForward
### accessForward<sup>(deprecated)</sup>
accessForward(): boolean
Checks whether going to the next page can be performed on the current page.
This API is deprecated since API version 9. You are advised to use [accessForward<sup>9+</sup>](../apis/js-apis-webview.md#accessforward).
**Return value**
| Type | Description |
...
...
@@ -3315,12 +3696,14 @@ Checks whether going to the next page can be performed on the current page.
}
```
### accessStep
### accessStep<sup>(deprecated)</sup>
accessStep(step: number): boolean
Performs a specific number of steps forward or backward from the current page.
This API is deprecated since API version 9. You are advised to use [accessStep<sup>9+</sup>](../apis/js-apis-webview.md#accessstep).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
...
...
@@ -3356,12 +3739,14 @@ Performs a specific number of steps forward or backward from the current page.
}
```
### backward
### backward<sup>(deprecated)</sup>
backward(): void
Goes to the previous page based on the history stack. This API is generally used together with **accessBackward**.
This API is deprecated since API version 9. You are advised to use [backward<sup>9+</sup>](../apis/js-apis-webview.md#backward).
**Example**
```ts
...
...
@@ -3383,12 +3768,14 @@ Goes to the previous page based on the history stack. This API is generally used
}
```
### forward
### forward<sup>(deprecated)</sup>
forward(): void
Goes to the next page based on the history stack. This API is generally used together with **accessForward**.
This API is deprecated since API version 9. You are advised to use [forward<sup>9+</sup>](../apis/js-apis-webview.md#forward).
**Example**
```ts
...
...
@@ -3444,12 +3831,14 @@ Performs a specific number of steps forward or backward on the current page base
Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refresh) API.
This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
...
...
@@ -3478,12 +3867,14 @@ Deletes a specific application JavaScript object that is registered with the win
}
```
### getHitTest
### getHitTest<sup>(deprecated)</sup>
getHitTest(): HitTestType
Obtains the element type of the area being clicked.
This API is deprecated since API version 9. You are advised to use [getHitTest<sup>9+</sup>](../apis/js-apis-webview.md#gethittest).
**Return value**
| Type | Description |
...
...
@@ -3678,7 +4069,7 @@ Obtains the default user agent of the current web page.
@@ -3688,6 +4079,8 @@ If **baseUrl** is set to a data URL, the encoded string will be loaded by the **
If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be processed by the **\<Web>** component as a non-encoded string in a manner similar to **loadUrl**.
This API is deprecated since API version 9. You are advised to use [loadData<sup>9+</sup>](../apis/js-apis-webview.md#loaddata).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
...
...
@@ -3723,7 +4116,7 @@ If **baseUrl** is set to an HTTP or HTTPS URL, the encoded string will be proces
Registers a JavaScript object and invokes the methods of the object in the window. You must invoke the [refresh](#refresh) API for the registration to take effect.
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refresh) API for the registration to take effect.
This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy).
**Parameters**
...
...
@@ -4007,12 +4412,14 @@ Registers a JavaScript object and invokes the methods of the object in the windo
Executes a JavaScript script. This API uses an asynchronous callback to return the script execution result. **runJavaScript** can be invoked only after **loadUrl** is executed. For example, it can be invoked in **onPageEnd**.
This API is deprecated since API version 9. You are advised to use [runJavaScript<sup>9+</sup>](../apis/js-apis-webview.md#runjavascript).
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
...
...
@@ -4066,12 +4473,14 @@ Executes a JavaScript script. This API uses an asynchronous callback to return t
```
### stop
### stop<sup>(deprecated)</sup>
stop()
Stops page loading.
This API is deprecated since API version 9. You are advised to use [stop<sup>9+</sup>](../apis/js-apis-webview.md#stop).
**Example**
```ts
...
...
@@ -4093,12 +4502,14 @@ Stops page loading.
}
```
### clearHistory
### clearHistory<sup>(deprecated)</sup>
clearHistory(): void
Clears the browsing history.
This API is deprecated since API version 9. You are advised to use [clearHistory<sup>9+</sup>](../apis/js-apis-webview.md#clearhistory).
**Example**
```ts
...
...
@@ -4626,7 +5037,7 @@ Obtains the cookie value corresponding to the specified URL.
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. |
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. |
| origin | string | Yes | - | Index of the origin. |
| callback | AsyncCallback\<boolean\> | Yes | - | Callback used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
| Promise\<boolean\> | Promise used to return the geolocation permission status of the specified source. If the operation is successful, the value **true** means that the geolocation permission is granted, and **false** means the opposite. If the operation fails, the geolocation permission status of the specified source is not found.|
Implements the **WebStorage** object, which can be used to manage the Web SQL and the HTML5 Web Storage API. All **\<Web>** components in an application share one **WebStorage**.
| callback | AsyncCallback<Array<[WebStorageOrigin](#webstorageorigin9)>> | Yes | Callback used to return the information about the origins. For details, see **WebStorageOrigin**.|
| Promise<Array<[WebStorageOrigin](#webstorageorigin9)>> | Promise used to return the information about the origins. For details, see **WebStorageOrigin**.|
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
| None | The cache is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet. |
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. |
## FileSelectorMode
| Name | Description |
| -------------------- | ---------- |
| FileOpenMode | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.|
| FileSaveMode | Save a file. |
## HitTestType
| Name | Description |
| ------------- | ------------------------ |
| EditText | Editable area. |
| Email | Email address. |
| HttpAnchor | Hyperlink whose **src** is **http**. |
| HttpAnchorImg | Image with a hyperlink, where **src** is **http**.|
| Img | HTML::img tag. |
| Map | Geographical address. |
| Phone | Phone number. |
| Unknown | Unknown content. |
## SslError<sup>9+</sup>
Enumerates the error codes returned by **onSslErrorEventReceive** API.
| Name | Description |
| ------------ | ----------- |
| Invalid | Minor error. |
| HostMismatch | The host name does not match. |
| DateInvalid | The certificate has an invalid date. |
| Untrusted | The certificate issuer is not trusted.|
| MidiSysex | MIDI SYSEX resource.| Currently, only permission events can be reported. MIDI devices are not yet supported.|
## WebAsyncController
Implements the **WebAsyncController** object, which can be used to control the behavior of a **\<Web>** component with asynchronous callbacks. A **WebAsyncController **object controls one **\<Web>** component.
### Creating an Object
```
webController: WebController = new WebController();
webAsyncController: WebAsyncController = new WebAsyncController(webController);
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.
| callback | AsyncCallback<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise.|
| baseName | string | Yes| Save path. The value cannot be null.
| autoName | boolean | Yes| Whether to automatically generate a file name.<br>The value **false** means not to automatically generate a file name.<br>The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.