未验证 提交 2eb44c59 编写于 作者: O openharmony_ci 提交者: Gitee

!17163 【挑单3.2-Release】翻译完成 16337+16713

Merge pull request !17163 from ester.zhou/cherry-pick-1681210204
...@@ -383,6 +383,8 @@ struct WebComponent { ...@@ -383,6 +383,8 @@ struct WebComponent {
} }
``` ```
There are two methods for loading local resource files:
1. Using $rawfile
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
...@@ -409,6 +411,8 @@ struct WebComponent { ...@@ -409,6 +411,8 @@ struct WebComponent {
} }
``` ```
2. Using a sandbox path. For details, see the example of loading local resource files in the sandbox in [Web](../arkui-ts/ts-basic-components-web.md#web).
```html ```html
<!-- xxx.html --> <!-- xxx.html -->
<!DOCTYPE html> <!DOCTYPE html>
......
...@@ -68,7 +68,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) ...@@ -68,7 +68,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
``` ```
Example of loading local resource files in the sandbox: Example of loading local resource files in the sandbox:
1. Use[globalthis](../../application-models/uiability-data-sync-with-ui.md#using-globalthis-between-uiability-and-page) to obtain the path of the sandbox. 1. Use [globalthis](../../application-models/uiability-data-sync-with-ui.md#using-globalthis-between-uiability-and-page) to obtain the path of the sandbox.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
...@@ -518,6 +518,8 @@ multiWindowAccess(multiWindow: boolean) ...@@ -518,6 +518,8 @@ multiWindowAccess(multiWindow: boolean)
Sets whether to enable the multi-window permission. Sets whether to enable the multi-window permission.
Enabling the multi-window permission requires implementation of the **onWindowNew** event. For details about the sample code, see [onWindowNew](#onwindownew9).
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -537,7 +539,7 @@ Sets whether to enable the multi-window permission. ...@@ -537,7 +539,7 @@ Sets whether to enable the multi-window permission.
build() { build() {
Column() { Column() {
Web({ src: 'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.multiWindowAccess(true) .multiWindowAccess(false)
} }
} }
} }
...@@ -2555,7 +2557,9 @@ Called when the component exits full screen mode. ...@@ -2555,7 +2557,9 @@ Called when the component exits full screen mode.
onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetUrl: string, handler: ControllerHandler}) => void) onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetUrl: string, handler: ControllerHandler}) => void)
Registers a callback for window creation. Called when a new window is created. This API takes effect when **multiWindowAccess** is enabled.
If the **event.handler.setWebController** API is not called, the render process will be blocked.
If opening a new window is not needed, set the parameter to **null** when calling the **event.handler.setWebController** API.
**Parameters** **Parameters**
...@@ -2571,19 +2575,50 @@ Registers a callback for window creation. ...@@ -2571,19 +2575,50 @@ Registers a callback for window creation.
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview' import web_webview from '@ohos.web.webview'
// There are two <Web> components on the same page. When the WebComponent object opens a new window, the NewWebViewComp object is displayed.
@CustomDialog
struct NewWebViewComp {
controller: CustomDialogController
webviewController1: web_webview.WebviewController
build() {
Column() {
Web({ src: "", controller: this.webviewController1 })
.javaScriptAccess(true)
.multiWindowAccess(false)
.onWindowExit(()=> {
console.info("NewWebViewComp onWindowExit")
this.controller.close()
})
}
}
}
@Entry @Entry
@Component @Component
struct WebComponent { struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController() controller: web_webview.WebviewController = new web_webview.WebviewController()
dialogController: CustomDialogController = null
build() { build() {
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src: 'www.example.com', controller: this.controller })
.multiWindowAccess(true) .javaScriptAccess(true)
.onWindowNew((event) => { // MultiWindowAccess needs to be enabled.
console.log("onWindowNew...") .multiWindowAccess(true)
var popController: web_webview.WebviewController = new web_webview.WebviewController() .onWindowNew((event) => {
event.handler.setWebController(popController) if (this.dialogController) {
}) this.dialogController.close()
}
let popController:web_webview.WebviewController = new web_webview.WebviewController()
this.dialogController = new CustomDialogController({
builder: NewWebViewComp({webviewController1: popController})
})
this.dialogController.open()
// Return the WebviewController object corresponding to the new window to the <Web> kernel.
// If opening a new window is not needed, set the parameter to null when calling the event.handler.setWebController API.
// If the event.handler.setWebController API is not called, the render process will be blocked.
event.handler.setWebController(popController)
})
} }
} }
} }
...@@ -2593,13 +2628,13 @@ Registers a callback for window creation. ...@@ -2593,13 +2628,13 @@ Registers a callback for window creation.
onWindowExit(callback: () => void) onWindowExit(callback: () => void)
Registers a callback for window closure. Called when this window is closed.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| -------- | ---------- | ------------ | | -------- | ---------- | ------------ |
| callback | () => void | Callback invoked when the window closes.| | callback | () => void | Callback invoked when the window is closed.|
**Example** **Example**
...@@ -2728,7 +2763,7 @@ Called when the old page is not displayed and the new page is about to be visibl ...@@ -2728,7 +2763,7 @@ Called when the old page is not displayed and the new page is about to be visibl
onInterceptKeyEvent(callback: (event: KeyEvent) => boolean) onInterceptKeyEvent(callback: (event: KeyEvent) => boolean)
Called when the key event is intercepted and before it is consumed by the Webview. Called when the key event is intercepted and before it is consumed by the webview.
**Parameters** **Parameters**
...@@ -2740,7 +2775,7 @@ Called when the key event is intercepted and before it is consumed by the Webvie ...@@ -2740,7 +2775,7 @@ Called when the key event is intercepted and before it is consumed by the Webvie
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ |
| boolean | Whether to continue to transfer the key event to the Webview kernel.| | boolean | Whether to continue to transfer the key event to the webview kernel.|
**Example** **Example**
...@@ -2932,13 +2967,13 @@ Implements a **WebviewController** object for new **\<Web>** components. For the ...@@ -2932,13 +2967,13 @@ Implements a **WebviewController** object for new **\<Web>** components. For the
setWebController(controller: WebviewController): void setWebController(controller: WebviewController): void
Sets a **WebviewController** object. Sets a **WebviewController** object. If opening a new window is not needed, set the parameter to **null**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| ---------- | ------------- | ---- | ---- | ------------------------- | | ---------- | ------------- | ---- | ---- | ------------------------- |
| controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes | - | **WebviewController** object of the **\<Web>** component.| | controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | Yes | - | **WebviewController** object of the **\<Web>** component. If opening a new window is not needed, set it to **null**.|
## WebResourceError ## WebResourceError
...@@ -3032,6 +3067,18 @@ Checks whether the resource request is associated with a gesture (for example, a ...@@ -3032,6 +3067,18 @@ Checks whether the resource request is associated with a gesture (for example, a
| ------- | -------------------- | | ------- | -------------------- |
| boolean | Whether the resource request is associated with a gesture (for example, a tap).| | boolean | Whether the resource request is associated with a gesture (for example, a tap).|
### getRequestMethod<sup>9+</sup>
getRequestMethod(): string
Obtains the request method.
**Return value**
| Type | Description |
| ------- | -------------------- |
| string | Request method.|
## Header ## Header
Describes the request/response header returned by the **\<Web>** component. Describes the request/response header returned by the **\<Web>** component.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册