openharmony 鸿蒙 arkts-apis-webview-BackForwardList

2026-08-25 浏览 (1)

Interface (BackForwardList)

Defines the backforward list of the current WebView.

NOTE

  • 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.

  • The initial APIs of this interface are supported since API version 9.

  • The sample effect is subject to the actual device.

Module to Import

import { webview } from '@kit.ArkWeb';

Attributes

System capability: SystemCapability.Web.Webview.Core

NameTypeRead-OnlyOptionalDescription
currentIndexnumberNoNoIndex of the current page in the backforward list.
sizenumberNoNoNumber 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.

getItemAtIndex

getItemAtIndex(index: number): HistoryItem

Obtains information about a history item with a specified index in the backforward list.

System capability: SystemCapability.Web.Webview.Core

Parameters

NameTypeMandatoryDescription
indexnumberYesIndex of the history item in the backforward list.

Returns

TypeDescription
HistoryItemHistory item.

Error codes

For details about the error codes, see Universal Error Codes.

Error CodeError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed.

Example

// xxx.ets
import { webview } from '@kit.ArkWeb';
import { BusinessError } from '@kit.BasicServicesKit';
import { image } from '@kit.ImageKit';

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();
  @State icon: image.PixelMap|undefined = undefined;

  build() {
    Column() {
      Button('getBackForwardEntries')
        .onClick(() => {
          try {
            let list = this.controller.getBackForwardEntries();
            let historyItem = list.getItemAtIndex(list.currentIndex);
            console.info("HistoryItem: " + JSON.stringify(historyItem));
            this.icon = historyItem.icon;
          } catch (error) {
            console.error(`ErrorCode: ${(error as BusinessError).code},  Message: ${(error as BusinessError).message}`);
          }
        })
      Web({ src: 'www.example.com', controller: this.controller })
    }
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 arkts-apis-webview-WebviewController

openharmony 鸿蒙 arkts-apis-webview-t

openharmony 鸿蒙 arkts-apis-webview

openharmony 鸿蒙 capi-arkweb-type-h

openharmony 鸿蒙 arkts-basic-components-web-FullScreenExitHandler

openharmony 鸿蒙 arkts-apis-webview-WebDownloadManager

openharmony 鸿蒙 arkts-basic-components-web-VerifyPinHandler

openharmony 鸿蒙 capi-web-arkweb-webmessage8h

openharmony 鸿蒙 arkts-apis-webview-NativeMediaPlayerHandler

openharmony 鸿蒙 capi-web-arkweb-proxymethodwithresult

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/Q8vbPUgs