# Class (WebController, deprecated) 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 [WebviewController9+](./arkts-apis-webview-WebviewController.md) instead. > **NOTE** > > - The initial APIs of this component are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. > > - The initial APIs of this class are supported since API version 8. > > - You can preview how this component looks on a real device, but not in DevEco Studio Previewer. ## Creating an Object ```ts let webController: WebController = new WebController() ``` ## constructor(deprecated) constructor() Constructs a **WebController** object. > **NOTE** > > This API is supported since API version 8 and deprecated since API version 9. No API is provided for substitute. **System capability**: SystemCapability.Web.Webview.Core ## getCookieManager(deprecated) getCookieManager(): WebCookie Obtains the cookie management object of the **Web** component. This API is deprecated since API version 9. You are advised to use [getCookie](./arkts-apis-webview-WebCookieManager.md#getcookiedeprecated) instead. **System capability**: SystemCapability.Web.Webview.Core **Return value** | Type | Description | | --------- | ---------------------------------------- | | WebCookie | Cookie management object of the **Web** component. For details, see [WebCookie](./arkts-basic-components-web-WebCookie.md).| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('getCookieManager') .onClick(() => { let cookieManager = this.controller.getCookieManager() }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## requestFocus(deprecated) requestFocus() Requests focus for this web page. This API is deprecated since API version 9. You are advised to use [requestFocus9+](./arkts-apis-webview-WebviewController.md#requestfocus) instead. **System capability**: SystemCapability.Web.Webview.Core **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('requestFocus') .onClick(() => { this.controller.requestFocus() }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## accessBackward(deprecated) 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 [accessBackward9+](./arkts-apis-webview-WebviewController.md#accessbackward) instead. **System capability**: SystemCapability.Web.Webview.Core **Return value** | Type | Description | | ------- | --------------------- | | boolean | **true** is returned if going to the previous page can be performed on the current page; otherwise, **false** is returned.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('accessBackward') .onClick(() => { let result = this.controller.accessBackward() console.log('result:' + result) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## accessForward(deprecated) 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 [accessForward9+](./arkts-apis-webview-WebviewController.md#accessforward) instead. **System capability**: SystemCapability.Web.Webview.Core **Return value** | Type | Description | | ------- | --------------------- | | boolean | If going to the next page can be performed on the current page, **true** is returned; otherwise, **false** is returned.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('accessForward') .onClick(() => { let result = this.controller.accessForward() console.log('result:' + result) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## accessStep(deprecated) 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 [accessStep9+](./arkts-apis-webview-WebviewController.md#accessstep) instead. **System capability**: SystemCapability.Web.Webview.Core **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | --------------------- | | step | number | Yes | Number of the steps to take. A positive number means to go forward, and a negative number means to go backward.| **Return value** | Type | Description | | ------- | --------- | | boolean | Whether going forward or backward from the current page is successful.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() @State steps: number = 2 build() { Column() { Button('accessStep') .onClick(() => { let result = this.controller.accessStep(this.steps) console.log('result:' + result) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## backward(deprecated) backward() 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 [backward9+](./arkts-apis-webview-WebviewController.md#backward) instead. **System capability**: SystemCapability.Web.Webview.Core **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('backward') .onClick(() => { this.controller.backward() }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## forward(deprecated) forward() 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 [forward9+](./arkts-apis-webview-WebviewController.md#forward) instead. **System capability**: SystemCapability.Web.Webview.Core **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('forward') .onClick(() => { this.controller.forward() }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## deleteJavaScriptRegister(deprecated) deleteJavaScriptRegister(name: string) 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](#refreshdeprecated) API. This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister9+](./arkts-apis-webview-WebviewController.md#deletejavascriptregister) instead. **System capability**: SystemCapability.Web.Webview.Core **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------------------------------- | | name | string | Yes | Name of the registered JavaScript object, which can be used to invoke the corresponding object on the application side from the web side.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() @State name: string = 'Object' build() { Column() { Button('deleteJavaScriptRegister') .onClick(() => { this.controller.deleteJavaScriptRegister(this.name) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## getHitTest(deprecated) getHitTest(): HitTestType Obtains the element type of the area being clicked. This API is deprecated since API version 9. You are advised to use [getHitTest9+](./arkts-apis-webview-WebviewController.md#gethittestdeprecated) instead. **System capability**: SystemCapability.Web.Webview.Core **Return value** | Type | Description | | ------------------------------- | ----------- | | [HitTestType](./arkts-basic-components-web-e.md#hittesttype) | Element type of the area being clicked.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('getHitTest') .onClick(() => { let hitType = this.controller.getHitTest() console.log("hitType: " + hitType) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## loadData(deprecated) loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }) Loads data. If **baseUrl** is empty, the specified character string will be loaded using the data protocol. If **baseUrl** is set to a data URL, the encoded string will be loaded by the **Web** component using the data protocol. 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 [loadData9+](./arkts-apis-webview-WebviewController.md#loaddata) instead. **System capability**: SystemCapability.Web.Webview.Core **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------ | ---- | ---------------------------------------- | | data | string | Yes | Character string obtained after being Base64 or URL encoded. | | mimeType | string | Yes | Media type (MIME). | | encoding | string | Yes | Encoding type, which can be Base64 or URL. | | baseUrl | string | No | URL (HTTP/HTTPS/data compliant), which is assigned by the **Web** component to **window.origin**.| | historyUrl | string | No | Historical record URL. If this parameter is not empty, it can be managed in historical records to implement page going backward and forward. This parameter is invalid when **baseUrl** is left empty.| **Example** ```ts // xxx.ets @Entry @Component struct WebComponent { controller: WebController = new WebController() build() { Column() { Button('loadData') .onClick(() => { this.controller.loadData({ data: "
Source:source", mimeType: "text/html", encoding: "UTF-8" }) }) Web({ src: 'www.example.com', controller: this.controller }) } } } ``` ## loadUrl(deprecated) loadUrl(options: { url: string | Resource, headers?: Array\