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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | string | Yes | Web event type. The value can be "webInited", indicating completion of web initialization. |
| callback | Callback<void> | Yes | Callback to register. |
Error codes
For details about the error codes, see Universal Error Codes.
| Error Code | Error Message |
|---|---|
| 401 | Parameter 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