• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (BackForwardList)
2
3Defines the backforward list of the current WebView.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> - The initial APIs of this interface are supported since API version 9.
10>
11> - You can preview how this component looks on a real device, but not in DevEco Studio Previewer.
12
13## Module to Import
14
15```ts
16import { webview } from '@kit.ArkWeb';
17```
18
19## Attributes
20
21**System capability**: SystemCapability.Web.Webview.Core
22
23| Name        | Type  | Read-Only| Optional| Description                                                        |
24| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
25| currentIndex | number | No  | No  | Index of the current page in the backforward list.                                |
26| size         | number | No  | No  | Number of indexes in the backforward list. A maximum of 50 indexes can be stored. If this limit is exceeded, the start records will be overwritten.|
27
28## getItemAtIndex
29
30getItemAtIndex(index: number): HistoryItem
31
32Obtains information about a history item with a specified index in the backforward list.
33
34**System capability**: SystemCapability.Web.Webview.Core
35
36**Parameters**
37
38| Name| Type  | Mandatory| Description                  |
39| ------ | ------ | ---- | ---------------------- |
40| index  | number | Yes  | Index of the history item in the backforward list.|
41
42**Returns**
43
44| Type                       | Description        |
45| --------------------------- | ------------ |
46| [HistoryItem](./arkts-apis-webview-i.md#historyitem) | History item.|
47
48**Error codes**
49
50For details about the error codes, see [Webview Error Codes](errorcode-webview.md).
51
52| Error Code| Error Message                                               |
53| -------- | ------------------------------------------------------ |
54| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. |
55
56**Example**
57
58```ts
59// xxx.ets
60import { webview } from '@kit.ArkWeb';
61import { BusinessError } from '@kit.BasicServicesKit';
62import { image } from '@kit.ImageKit';
63
64@Entry
65@Component
66struct WebComponent {
67  controller: webview.WebviewController = new webview.WebviewController();
68  @State icon: image.PixelMap | undefined = undefined;
69
70  build() {
71    Column() {
72      Button('getBackForwardEntries')
73        .onClick(() => {
74          try {
75            let list = this.controller.getBackForwardEntries();
76            let historyItem = list.getItemAtIndex(list.currentIndex);
77            console.log("HistoryItem: " + JSON.stringify(historyItem));
78            this.icon = historyItem.icon;
79          } catch (error) {
80            console.error(`ErrorCode: ${(error as BusinessError).code},  Message: ${(error as BusinessError).message}`);
81          }
82        })
83      Web({ src: 'www.example.com', controller: this.controller })
84    }
85  }
86}
87```
88