openharmony 鸿蒙 arkts-apis-webview-f

2026-08-25 浏览 (1)

Functions

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 sample effect is subject to the actual device.

Module to Import

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

webview.once

once(type: string, callback: Callback<void>): void

Registers a one-time callback for web events of the specified type. Currently, only webInited is supported. This callback is triggered when the Web engine initialization is complete.

When the first Web component is loaded in an application, the web engine is initialized. When other Web components are loaded in the same application, once() is not triggered. When the first Web component is loaded after the last Web component is destroyed in the application, the web engine will be initialized again.

System capability: SystemCapability.Web.Webview.Core

Parameters

NameTypeMandatoryDescription
typestringYesWeb event type. The value can be "webInited", indicating completion of web initialization.
callbackCallback<void>YesCallback to register.

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';

webview.once("webInited", () => {
  console.info("configCookieSync");
  webview.WebCookieManager.configCookieSync("https://www.example.com", "a=b");
})

@Entry
@Component
struct WebComponent {
  controller: webview.WebviewController = new webview.WebviewController();

  build() {
    Column() {
      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/ciYmubbb