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 7fb4883b994b1fe4f52db30a76b1c055c7a1e829..f9e4af6780992289271fae94f73ecf02400379d2 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-webview.md +++ b/zh-cn/application-dev/reference/apis/js-apis-webview.md @@ -3167,7 +3167,7 @@ static getCookie(url: string): string | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | :------------------------ | -| url | string | 是 | 要获取的cookie所属的url。 | +| url | string | 是 | 要获取的cookie所属的url,建议使用完整的url。 | **返回值:** @@ -3223,7 +3223,7 @@ static setCookie(url: string, value: string): void | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | :------------------------ | -| url | string | 是 | 要设置的cookie所属的url。 | +| url | string | 是 | 要设置的cookie所属的url,建议使用完整的url。 | | value | string | 是 | 要设置的cookie的值。 | **错误码:** 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 8a8a498c5343a28c971c84ce4048240997f34336..ce28e61d583fa2e7a3ffc0a0076e7109eab30dca 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 @@ -27,7 +27,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) | 参数名 | 参数类型 | 必填 | 参数描述 | | ---------- | ---------------------------------------- | ---- | ------- | -| src | [ResourceStr](ts-types.md) | 是 | 网页资源地址。 | +| src | [ResourceStr](ts-types.md) | 是 | 网页资源地址。如果加载应用包外沙箱路径的本地资源文件,请使用file://沙箱文件路径。 | | controller | [WebviewController9+](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | 是 | 控制器。从API Version 9开始,WebController不在维护,建议使用WebviewController替代。 | **示例:** @@ -64,6 +64,43 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController}) } ``` + 加载沙箱路径下的本地资源文件 + + 1.通过[globalthis](../../application-models/uiability-data-sync-with-ui.md#uiability和page之间使用globalthis)获取沙箱路径。 + ```ts + // xxx.ets + import web_webview from '@ohos.web.webview' + let url = 'file://' + globalThis.filesDir + '/xxx.html' + + @Entry + @Component + struct WebComponent { + controller: web_webview.WebviewController = new web_webview.WebviewController() + build() { + Column() { + // 加载沙箱路径文件。 + Web({ src: url, controller: this.controller }) + } + } + } + ``` + + 2.修改MainAbility.ts。 + 以filesDir为例,获取沙箱路径。若想获取其他路径,请参考[应用开发路径](../../application-models/application-context-stage.md#获取应用开发路径)。 + ```ts + // xxx.ts + import UIAbility from '@ohos.app.ability.UIAbility'; + import web_webview from '@ohos.web.webview'; + + export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // 通过在globalThis对象上绑定filesDir,可以实现UIAbility组件与UI之间的数据同步。 + globalThis.filesDir = this.context.filesDir + console.log("Sandbox path is " + globalThis.filesDir) + } + } + ``` + ```html @@ -4928,7 +4965,7 @@ setCookie(url: string, value: string): boolean | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | ----- | ------ | ---- | ---- | ----------------- | -| url | string | 是 | - | 要设置的cookie所属的url。 | +| url | string | 是 | - | 要设置的cookie所属的url,建议使用完整的url。 | | value | string | 是 | - | cookie的值。 | **返回值:**