From f67e885796358d28187e5cd9521d93083b54c90e Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 21 Mar 2023 16:34:32 +0800 Subject: [PATCH] Add a description of the loadUrl loading sandbox path Signed-off-by: lixiang --- .../reference/apis/js-apis-webview.md | 4 ++ .../arkui-ts/ts-basic-components-web.md | 56 +++++++++++++++---- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-webview.md b/zh-cn/application-dev/reference/apis/js-apis-webview.md index 92fcd907e6..8575b87e39 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-webview.md +++ b/zh-cn/application-dev/reference/apis/js-apis-webview.md @@ -382,6 +382,8 @@ struct WebComponent { } ``` +加载本地网页,加载本地资源文件有两种方式。 +1.$rawfile方式。 ```ts // xxx.ets import web_webview from '@ohos.web.webview' @@ -408,6 +410,8 @@ struct WebComponent { } ``` +2.加载沙箱路径下的本地资源文件,可以参考[web](../arkui-ts/ts-basic-components-web.md#web)加载沙箱路径的示例代码。 + ```html diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md index 2d862a5a93..b03b04f51f 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md @@ -516,6 +516,7 @@ mediaPlayGestureAccess(access: boolean) multiWindowAccess(multiWindow: boolean) 设置是否开启多窗口权限,默认不开启。 +使能多窗口权限时,需要实现onWindowNew事件,示例代码参考[onWindowNew事件](#onwindownew9)。 **参数:** @@ -536,7 +537,7 @@ multiWindowAccess(multiWindow: boolean) build() { Column() { Web({ src: 'www.example.com', controller: this.controller }) - .multiWindowAccess(true) + .multiWindowAccess(false) } } } @@ -2552,7 +2553,9 @@ onFullScreenExit(callback: () => void) onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetUrl: string, handler: ControllerHandler}) => void) -通知用户新建窗口请求。 +使能multiWindowAccess情况下,通知用户新建窗口请求。 +若不调用event.handler.setWebController接口,会造成render进程阻塞。 +如果不需要打开新窗口,在调用event.handler.setWebController接口时须设置成null。 **参数:** @@ -2568,19 +2571,50 @@ onWindowNew(callback: (event: {isAlert: boolean, isUserTrigger: boolean, targetU ```ts // xxx.ets import web_webview from '@ohos.web.webview' + + //在同一page页有两个web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 + @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 @Component struct WebComponent { controller: web_webview.WebviewController = new web_webview.WebviewController() + dialogController: CustomDialogController = null build() { Column() { - Web({ src:'www.example.com', controller: this.controller }) - .multiWindowAccess(true) - .onWindowNew((event) => { - console.log("onWindowNew...") - var popController: web_webview.WebviewController = new web_webview.WebviewController() - event.handler.setWebController(popController) - }) + Web({ src: 'www.example.com', controller: this.controller }) + .javaScriptAccess(true) + //需要使能multiWindowAccess + .multiWindowAccess(true) + .onWindowNew((event) => { + 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() + //将新窗口对应WebviewController返回给Web内核。 + //如果不需要打开新窗口请调用event.handler.setWebController接口设置成null。 + //若不调用event.handler.setWebController接口,会造成render进程阻塞。 + event.handler.setWebController(popController) + }) } } } @@ -2929,13 +2963,13 @@ exitFullScreen(): void setWebController(controller: WebviewController): void -设置WebviewController对象。 +设置WebviewController对象,如果不需要打开新窗口请设置为null。 **参数:** | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | ---------- | ------------- | ---- | ---- | ------------------------- | -| controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | 是 | - | 新建web组件的的WebviewController对象。 | +| controller | [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | 是 | - | 新建web组件的的WebviewController对象,如果不需要打开新窗口请设置为null。 | ## WebResourceError -- GitLab