Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
299b725a
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
299b725a
编写于
1月 10, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 10, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13376 修复资料web.d.ts资料不对应及接口废弃描述补充(主干)
Merge pull request !13376 from Ted/master
上级
2bbc7357
f8ab97c3
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
118 addition
and
967 deletion
+118
-967
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+118
-967
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
299b725a
...
@@ -1763,7 +1763,7 @@ onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean
...
@@ -1763,7 +1763,7 @@ onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean
}
}
```
```
### onRenderExited
### onRenderExited
<sup>9+</sup>
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
...
@@ -3539,24 +3539,28 @@ invoke(origin: string, allow: boolean, retain: boolean): void
...
@@ -3539,24 +3539,28 @@ invoke(origin: string, allow: boolean, retain: boolean): void
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
| origin | string | 是 | - | 指定源的字符串索引。 |
| allow | boolean | 是 | - | 设置的地理位置权限状态。 |
| allow | boolean | 是 | - | 设置的地理位置权限状态。 |
| retain | boolean | 是 | - | 是否允许将地理位置权限状态保存到系统中。可通过
[
GeolocationPermissions
](
#geolocationpermissions9
)
接口管理保存到系统的地理位置权限。 |
| retain | boolean | 是 | - | 是否允许将地理位置权限状态保存到系统中。可通过
[
GeolocationPermissions
<sup>9+</sup>
](
../apis/js-apis-webview.md#geolocationpermissions
)
接口管理保存到系统的地理位置权限。 |
## WebController
## WebController
通过WebController可以控制Web组件各种行为。一个WebController对象只能控制一个Web组件,且必须在Web组件和WebController绑定后,才能调用WebController上的方法。
通过WebController可以控制Web组件各种行为。一个WebController对象只能控制一个Web组件,且必须在Web组件和WebController绑定后,才能调用WebController上的方法。
从API version 9开始不再维护,建议使用
[
WebviewController<sup>9+</sup>
](
../apis/js-apis-webview.md#webviewcontroller
)
代替。
### 创建对象
### 创建对象
```
```
webController: WebController = new WebController()
webController: WebController = new WebController()
```
```
### requestFocus
### requestFocus
<sup>(deprecated)</sup>
requestFocus()
requestFocus()
使当前web页面获取焦点。
使当前web页面获取焦点。
从API version 9开始不再维护,建议使用
[
requestFocus<sup>9+</sup>
](
../apis/js-apis-webview.md#requestfocus
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -3578,12 +3582,14 @@ requestFocus()
...
@@ -3578,12 +3582,14 @@ requestFocus()
}
}
```
```
### accessBackward
### accessBackward
<sup>(deprecated)</sup>
accessBackward(): boolean
accessBackward(): boolean
当前页面是否可后退,即当前页面是否有返回历史记录。
当前页面是否可后退,即当前页面是否有返回历史记录。
从API version 9开始不再维护,建议使用
[
accessBackward<sup>9+</sup>
](
../apis/js-apis-webview.md#accessbackward
)
代替。
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
...
@@ -3612,12 +3618,14 @@ accessBackward(): boolean
...
@@ -3612,12 +3618,14 @@ accessBackward(): boolean
}
}
```
```
### accessForward
### accessForward
<sup>(deprecated)</sup>
accessForward(): boolean
accessForward(): boolean
当前页面是否可前进,即当前页面是否有前进历史记录。
当前页面是否可前进,即当前页面是否有前进历史记录。
从API version 9开始不再维护,建议使用
[
accessForward<sup>9+</sup>
](
../apis/js-apis-webview.md#accessforward
)
代替。
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
...
@@ -3646,12 +3654,14 @@ accessForward(): boolean
...
@@ -3646,12 +3654,14 @@ accessForward(): boolean
}
}
```
```
### accessStep
### accessStep
<sup>(deprecated)</sup>
accessStep(step: number): boolean
accessStep(step: number): boolean
当前页面是否可前进或者后退给定的step步。
当前页面是否可前进或者后退给定的step步。
从API version 9开始不再维护,建议使用
[
accessStep<sup>9+</sup>
](
../apis/js-apis-webview.md#accessstep
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -3687,12 +3697,14 @@ accessStep(step: number): boolean
...
@@ -3687,12 +3697,14 @@ accessStep(step: number): boolean
}
}
```
```
### backward
### backward
<sup>(deprecated)</sup>
backward(): void
backward(): void
按照历史栈,后退一个页面。一般结合accessBackward一起使用。
按照历史栈,后退一个页面。一般结合accessBackward一起使用。
从API version 9开始不再维护,建议使用
[
backward<sup>9+</sup>
](
../apis/js-apis-webview.md#backward
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -3714,12 +3726,14 @@ backward(): void
...
@@ -3714,12 +3726,14 @@ backward(): void
}
}
```
```
### forward
### forward
<sup>(deprecated)</sup>
forward(): void
forward(): void
按照历史栈,前进一个页面。一般结合accessForward一起使用。
按照历史栈,前进一个页面。一般结合accessForward一起使用。
从API version 9开始不再维护,建议使用
[
forward<sup>9+</sup>
](
../apis/js-apis-webview.md#forward
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -3775,12 +3789,14 @@ backOrForward(step: number): void
...
@@ -3775,12 +3789,14 @@ backOrForward(step: number): void
}
}
```
```
### deleteJavaScriptRegister
### deleteJavaScriptRegister
<sup>(deprecated)</sup>
deleteJavaScriptRegister(name: string)
deleteJavaScriptRegister(name: string)
删除通过registerJavaScriptProxy注册到window上的指定name的应用侧JavaScript对象。删除后立即生效,无须调用
[
refresh
](
#refresh
)
接口。
删除通过registerJavaScriptProxy注册到window上的指定name的应用侧JavaScript对象。删除后立即生效,无须调用
[
refresh
](
#refresh
)
接口。
从API version 9开始不再维护,建议使用
[
deleteJavaScriptRegister<sup>9+</sup>
](
../apis/js-apis-webview.md#deletejavascriptregister
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -3809,12 +3825,14 @@ deleteJavaScriptRegister(name: string)
...
@@ -3809,12 +3825,14 @@ deleteJavaScriptRegister(name: string)
}
}
```
```
### getHitTest
### getHitTest
<sup>(deprecated)</sup>
getHitTest(): HitTestType
getHitTest(): HitTestType
获取当前被点击区域的元素类型。
获取当前被点击区域的元素类型。
从API version 9开始不再维护,建议使用
[
getHitTest<sup>9+</sup>
](
../apis/js-apis-webview.md#gethittest
)
代替。
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
...
@@ -4009,7 +4027,7 @@ getDefaultUserAgent(): string
...
@@ -4009,7 +4027,7 @@ getDefaultUserAgent(): string
}
}
```
```
### loadData
### loadData
<sup>(deprecated)</sup>
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
...
@@ -4019,6 +4037,8 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
...
@@ -4019,6 +4037,8 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
当baseUrl为“http/https"协议时,编码后的data字符串将被Web组件以类似loadUrl的方式以非编码字符串处理。
当baseUrl为“http/https"协议时,编码后的data字符串将被Web组件以类似loadUrl的方式以非编码字符串处理。
从API version 9开始不再维护,建议使用
[
loadData<sup>9+</sup>
](
../apis/js-apis-webview.md#loaddata
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -4054,7 +4074,7 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
...
@@ -4054,7 +4074,7 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
}
}
```
```
### loadUrl
### loadUrl
<sup>(deprecated)</sup>
loadUrl(options: { url: string | Resource, headers?: Array
\<
Header
\>
})
loadUrl(options: { url: string | Resource, headers?: Array
\<
Header
\>
})
...
@@ -4064,6 +4084,8 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
...
@@ -4064,6 +4084,8 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
而通过registerJavaScriptProxy注入的对象,在loadUrl导航到新的页面也会有效。
而通过registerJavaScriptProxy注入的对象,在loadUrl导航到新的页面也会有效。
从API version 9开始不再维护,建议使用
[
loadUrl<sup>9+</sup>
](
../apis/js-apis-webview.md#loadurl
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -4092,12 +4114,14 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
...
@@ -4092,12 +4114,14 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
}
}
```
```
### onActive
### onActive
<sup>(deprecated)</sup>
onActive(): void
onActive(): void
调用此接口通知Web组件进入前台激活状态。
调用此接口通知Web组件进入前台激活状态。
从API version 9开始不再维护,建议使用
[
onActive<sup>9+</sup>
](
../apis/js-apis-webview.md#onactive
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -4119,12 +4143,14 @@ onActive(): void
...
@@ -4119,12 +4143,14 @@ onActive(): void
}
}
```
```
### onInactive
### onInactive
<sup>(deprecated)</sup>
onInactive(): void
onInactive(): void
调用此接口通知Web组件进入未激活状态。
调用此接口通知Web组件进入未激活状态。
从API version 9开始不再维护,建议使用
[
onInactive<sup>9+</sup>
](
../apis/js-apis-webview.md#oninactive
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -4146,11 +4172,13 @@ onInactive(): void
...
@@ -4146,11 +4172,13 @@ onInactive(): void
}
}
```
```
### zoom
### zoom
<sup>(deprecated)</sup>
zoom(factor: number): void
zoom(factor: number): void
调整当前网页的缩放比例。
调整当前网页的缩放比例。
从API version 9开始不再维护,建议使用
[
zoom<sup>9+</sup>
](
../apis/js-apis-webview.md#zoom
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
...
@@ -4245,12 +4273,14 @@ zoomOut(): boolean
...
@@ -4245,12 +4273,14 @@ zoomOut(): boolean
}
}
```
```
### refresh
### refresh
<sup>(deprecated)</sup>
refresh()
refresh()
调用此接口通知Web组件刷新网页。
调用此接口通知Web组件刷新网页。
从API version 9开始不再维护,建议使用
[
refresh<sup>9+</sup>
](
../apis/js-apis-webview.md#refresh
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -4272,12 +4302,14 @@ refresh()
...
@@ -4272,12 +4302,14 @@ refresh()
}
}
```
```
### registerJavaScriptProxy
### registerJavaScriptProxy
<sup>(deprecated)</sup>
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array
\<
string
\>
})
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array
\<
string
\>
})
注入JavaScript对象到window对象中,并在window对象中调用该对象的方法。注册后,须调用
[
refresh
](
#refresh
)
接口生效。
注入JavaScript对象到window对象中,并在window对象中调用该对象的方法。注册后,须调用
[
refresh
](
#refresh
)
接口生效。
从API version 9开始不再维护,建议使用
[
registerJavaScriptProxy<sup>9+</sup>
](
../apis/js-apis-webview.md#registerjavascriptproxy
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -4338,12 +4370,14 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
...
@@ -4338,12 +4370,14 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
```
```
### runJavaScript
### runJavaScript
<sup>(deprecated)</sup>
runJavaScript(options: { script: string, callback?: (result: string) => void })
runJavaScript(options: { script: string, callback?: (result: string) => void })
异步执行JavaScript脚本,并通过回调方式返回脚本执行的结果。runJavaScript需要在loadUrl完成后,比如onPageEnd中调用。
异步执行JavaScript脚本,并通过回调方式返回脚本执行的结果。runJavaScript需要在loadUrl完成后,比如onPageEnd中调用。
从API version 9开始不再维护,建议使用
[
runJavaScript<sup>9+</sup>
](
../apis/js-apis-webview.md#runjavascript
)
代替。
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
@@ -4397,12 +4431,14 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
...
@@ -4397,12 +4431,14 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
```
```
### stop
### stop
<sup>(deprecated)</sup>
stop()
stop()
停止页面加载。
停止页面加载。
从API version 9开始不再维护,建议使用
[
stop<sup>9+</sup>
](
../apis/js-apis-webview.md#stop
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -4424,12 +4460,14 @@ stop()
...
@@ -4424,12 +4460,14 @@ stop()
}
}
```
```
### clearHistory
### clearHistory
<sup>(deprecated)</sup>
clearHistory(): void
clearHistory(): void
删除所有前进后退记录。
删除所有前进后退记录。
从API version 9开始不再维护,建议使用
[
clearHistory<sup>9+</sup>
](
../apis/js-apis-webview.md#clearhistory
)
代替。
**示例:**
**示例:**
```
ts
```
ts
...
@@ -5007,40 +5045,6 @@ setCookie(url: string, value: string): boolean
...
@@ -5007,40 +5045,6 @@ setCookie(url: string, value: string): boolean
}
}
```
```
### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
将当前存在内存中的cookie保存到磁盘中,该方法为同步方法。
**返回值:**
| 类型 | 说明 |
| ------- | -------------------- |
| boolean | 同步内存cookie到磁盘操作是否成功。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
saveCookieSync
'
)
.
onClick
(()
=>
{
let
result
=
web_webview
.
WebCookieManager
.
saveCookieSync
()
console
.
log
(
"
result:
"
+
result
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### saveCookieAsync<sup>9+</sup>
### saveCookieAsync<sup>9+</sup>
saveCookieAsync(): Promise
\<
boolean>
saveCookieAsync(): Promise
\<
boolean>
...
@@ -5337,837 +5341,81 @@ deleteSessionCookie(): void
...
@@ -5337,837 +5341,81 @@ deleteSessionCookie(): void
}
}
```
```
## WebDataBase<sup>9+</sup>
## MessageLevel枚举说明
web组件数据库管理对象。
### existHttpAuthCredentials<sup>9+</sup>
static existHttpAuthCredentials(): boolean
判断是否存在任何已保存的HTTP身份验证凭据,该方法为同步方法。存在返回true,不存在返回false。
**返回值:**
| 类型 | 说明 |
| ------- | ---------------------------------------- |
| boolean | 是否存在任何已保存的HTTP身份验证凭据。存在返回true,不存在返回false |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
existHttpAuthCredentials
'
)
.
onClick
(()
=>
{
let
result
=
web_webview
.
WebDataBase
.
existHttpAuthCredentials
()
console
.
log
(
'
result:
'
+
result
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### deleteHttpAuthCredentials<sup>9+</sup>
static deleteHttpAuthCredentials(): void
清除所有已保存的HTTP身份验证凭据,该方法为同步方法。
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
deleteHttpAuthCredentials
'
)
.
onClick
(()
=>
{
web_webview
.
WebDataBase
.
deleteHttpAuthCredentials
()
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getHttpAuthCredentials<sup>9+</sup>
static getHttpAuthCredentials(host: string, realm: string): Array
\<
string
\>
检索给定主机和域的HTTP身份验证凭据,该方法为同步方法。检索成功返回一个包含用户名和密码的组数,检索不成功返回空数组。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----- | ------ | ---- | ---- | ---------------- |
| host | string | 是 | - | HTTP身份验证凭据应用的主机。 |
| realm | string | 是 | - | HTTP身份验证凭据应用的域。 |
**返回值:**
| 类型 | 说明 |
| --------------- | ---------------------- |
| Array
\<
string
\>
| 包含用户名和密码的组数,检索失败返回空数组。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
host
:
string
=
"
www.spincast.org
"
realm
:
string
=
"
protected example
"
username_password
:
string
[]
build
()
{
Column
()
{
Button
(
'
getHttpAuthCredentials
'
)
.
onClick
(()
=>
{
this
.
username_password
=
web_webview
.
WebDataBase
.
getHttpAuthCredentials
(
this
.
host
,
this
.
realm
)
console
.
log
(
'
num:
'
+
this
.
username_password
.
length
)
ForEach
(
this
.
username_password
,
(
item
)
=>
{
console
.
log
(
'
username_password:
'
+
item
)
},
item
=>
item
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### saveHttpAuthCredentials<sup>9+</sup>
static saveHttpAuthCredentials(host: string, realm: string, username: string, password: string): void
保存给定主机和域的HTTP身份验证凭据,该方法为同步方法。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | ------ | ---- | ---- | ---------------- |
| host | string | 是 | - | HTTP身份验证凭据应用的主机。 |
| realm | string | 是 | - | HTTP身份验证凭据应用的域。 |
| username | string | 是 | - | 用户名。 |
| password | string | 是 | - | 密码。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
host
:
string
=
"
www.spincast.org
"
realm
:
string
=
"
protected example
"
build
()
{
Column
()
{
Button
(
'
saveHttpAuthCredentials
'
)
.
onClick
(()
=>
{
web_webview
.
WebDataBase
.
saveHttpAuthCredentials
(
this
.
host
,
this
.
realm
,
"
Stromgol
"
,
"
Laroche
"
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
## GeolocationPermissions<sup>9+</sup>
| 名称 | 描述 |
| ----- | :---- |
| Debug | 调试级别。 |
| Error | 错误级别。 |
| Info | 消息级别。 |
| Log | 日志级别。 |
| Warn | 警告级别。 |
web组件地理位置权限管理对象。
## RenderExitReason枚举说明
### allowGeolocation<sup>9+</sup>
onRenderExited接口返回的渲染进程退出的具体原因。
static allowGeolocation(origin: string): void
| 名称 | 描述 |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | 渲染进程异常退出。 |
| ProcessWasKilled | 收到SIGKILL,或被手动终止。 |
| ProcessCrashed | 渲染进程崩溃退出,如段错误。 |
| ProcessOom | 程序内存不足。 |
| ProcessExitUnknown | 其他原因。 |
允许指定来源使用地理位置接口。
## MixedMode枚举说明
**参数:**
| 名称 | 描述 |
| ---------- | ---------------------------------- |
| All | 允许加载HTTP和HTTPS混合内容。所有不安全的内容都可以被加载。 |
| Compatible | 混合内容兼容性模式,部分不安全的内容可能被加载。 |
| None | 不允许加载HTTP和HTTPS混合内容。 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
## CacheMode枚举说明
| ------ | ------ | ---- | ---- | ---------- |
| 名称 | 描述 |
| origin | string | 是 | - | 指定源的字符串索引。 |
| ------- | ------------------------------------ |
| Default | 使用未过期的cache加载资源,如果cache中无该资源则从网络中获取。 |
| None | 加载资源使用cache,如果cache中无该资源则从网络中获取。 |
| Online | 加载资源不使用cache,全部从网络中获取。 |
| Only | 只从cache中加载资源。 |
**示例:**
## FileSelectorMode枚举说明
| 名称 | 描述 |
| -------------------- | ---------- |
| FileOpenMode | 打开上传单个文件。 |
| FileOpenMultipleMode | 打开上传多个文件。 |
| FileOpenFolderMode | 打开上传文件夹模式。 |
| FileSaveMode | 文件保存模式。 |
```
ts
## HitTestType枚举说明
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
file:///
"
build
()
{
Column
()
{
Button
(
'
allowGeolocation
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
allowGeolocation
(
this
.
origin
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### deleteGeolocation<sup>9+</sup>
| 名称 | 描述 |
| ------------- | ------------------------ |
| EditText | 可编辑的区域。 |
| Email | 电子邮件地址。 |
| HttpAnchor | 超链接,其src为http。 |
| HttpAnchorImg | 带有超链接的图片,其中超链接的src为http。 |
| Img | HTML::img标签。 |
| Map | 地理地址。 |
| Phone | 电话号码。 |
| Unknown | 未知内容。 |
static deleteGeolocation(origin: string): void
## SslError<sup>9+</sup>枚举说明
清除指定来源的地理位置权限状态
。
onSslErrorEventReceive接口返回的SSL错误的具体原因
。
**参数:**
| 名称 | 描述 |
| ------------ | ----------- |
| Invalid | 一般错误。 |
| HostMismatch | 主机名不匹配。 |
| DateInvalid | 证书日期无效。 |
| Untrusted | 证书颁发机构不受信任。 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
## ProtectedResourceType<sup>9+</sup>枚举说明
| ------ | ------ | ---- | ---- | ---------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
**示例:**
| 名称 | 描述 | 备注 |
| --------- | ------------- | -------------------------- |
```
ts
| MidiSysex | MIDI SYSEX资源。 | 目前仅支持权限事件上报,MIDI设备的使用还未支持。 |
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
file:///
"
build
()
{
Column
()
{
Button
(
'
deleteGeolocation
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
deleteGeolocation
(
this
.
origin
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### deleteAllGeolocation<sup>9+</sup>
static deleteAllGeolocation(): void
清除所有来源的地理位置权限状态。
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
deleteAllGeolocation
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
deleteAllGeolocation
()
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getAccessibleGeolocation<sup>9+</sup>
static getAccessibleGeolocation(origin: string, callback: AsyncCallback
\<
boolean
\>
): void
以回调方式异步获取指定源的地理位置权限状态。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | ------------------------ | ---- | ---- | ---------------------------------------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
| callback | AsyncCallback
\<
boolean
\>
| 是 | - | 返回指定源的地理位置权限状态。获取成功,true表示已授权,false表示拒绝访问。获取失败,表示不存在指定源的权限状态。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
file:///
"
build
()
{
Column
()
{
Button
(
'
getAccessibleGeolocationAsync
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
getAccessibleGeolocation
(
this
.
origin
,
(
error
,
result
)
=>
{
if
(
error
)
{
console
.
log
(
'
getAccessibleGeolocationAsync error:
'
+
JSON
.
stringify
(
error
))
return
}
console
.
log
(
'
getAccessibleGeolocationAsync result:
'
+
result
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getAccessibleGeolocation<sup>9+</sup>
static getAccessibleGeolocation(origin: string): Promise
\<
boolean
\>
以Promise方式异步获取指定源的地理位置权限状态。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ------ | ------ | ---- | ---- | ---------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
**返回值:**
| 类型 | 说明 |
| ------------------ | ---------------------------------------- |
| Promise
\<
boolean
\>
| Promise实例,用于获取指定源的权限状态,获取成功,true表示已授权,false表示拒绝访问。获取失败,表示不存在指定源的权限状态。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
file:///
"
build
()
{
Column
()
{
Button
(
'
getAccessibleGeolocationPromise
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
getAccessibleGeolocation
(
this
.
origin
).
then
(
result
=>
{
console
.
log
(
'
getAccessibleGeolocationPromise result:
'
+
result
)
}).
catch
(
error
=>
{
console
.
log
(
'
getAccessibleGeolocationPromise error:
'
+
JSON
.
stringify
(
error
))
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getStoredGeolocation<sup>9+</sup>
static getStoredGeolocation(callback: AsyncCallback
\<
Array
\<
string
\>\>
): void
以回调方式异步获取已存储地理位置权限状态的所有源信息。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------------------------------- | ---- | ---- | -------------------- |
| callback | AsyncCallback
\<
Array
\<
string
\>\>
| 是 | - | 返回已存储地理位置权限状态的所有源信息。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
getStoredGeolocationAsync
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
getStoredGeolocation
((
error
,
origins
)
=>
{
if
(
error
)
{
console
.
log
(
'
getStoredGeolocationAsync error:
'
+
JSON
.
stringify
(
error
))
return
}
let
origins_str
:
string
=
origins
.
join
()
console
.
log
(
'
getStoredGeolocationAsync origins:
'
+
origins_str
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getStoredGeolocation<sup>9+</sup>
static getStoredGeolocation(): Promise
\<
Array
\<
string
\>\>
以Promise方式异步获取已存储地理位置权限状态的所有源信息。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------------------------------- | ---- | ---- | -------------------- |
| callback | AsyncCallback
\<
Array
\<
string
\>\>
| 是 | - | 返回已存储地理位置权限状态的所有源信息。 |
**返回值:**
| 类型 | 说明 |
| -------------------------- | -------------------------------- |
| Promise
\<
Array
\<
string
\>\>
| Promise实例,用于获取已存储地理位置权限状态的所有源信息。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
getStoredGeolocationPromise
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
getStoredGeolocation
().
then
(
origins
=>
{
let
origins_str
:
string
=
origins
.
join
()
console
.
log
(
'
getStoredGeolocationPromise origins:
'
+
origins_str
)
}).
catch
(
error
=>
{
console
.
log
(
'
getStoredGeolocationPromise error:
'
+
JSON
.
stringify
(
error
))
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
## WebStorage<sup>9+</sup>
通过WebStorage可管理Web SQL数据库接口和HTML5 Web存储接口,每个应用中的所有Web组件共享一个WebStorage。
### deleteAllData<sup>9+</sup>
static deleteAllData(): void
清除Web SQL数据库当前使用的所有存储。
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
deleteAllData
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
deleteAllData
()
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### deleteOrigin<sup>9+</sup>
static deleteOrigin(origin : string): void
清除指定源所使用的存储。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- |
| origin | string | 是 | 指定源的字符串索引。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getHttpAuthCredentials
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
deleteOrigin
(
this
.
origin
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOrigins<sup>9+</sup>
static getOrigins(callback: AsyncCallback
\<
Array
\<
WebStorageOrigin>>) : void
以回调方式异步获取当前使用Web SQL数据库的所有源的信息。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback
<Array
<[
WebStorageOrigin
](
#webstorageorigin9
)
>
> | 是 | 以数组方式返回源的信息,信息内容参考WebStorageOrigin。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOrigins
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOrigins
((
error
,
origins
)
=>
{
if
(
error
)
{
console
.
log
(
'
error:
'
+
error
)
return
}
for
(
let
i
=
0
;
i
<
origins
.
length
;
i
++
)
{
console
.
log
(
'
origin:
'
+
origins
[
i
].
origin
)
console
.
log
(
'
usage:
'
+
origins
[
i
].
usage
)
console
.
log
(
'
quota:
'
+
origins
[
i
].
quota
)
}
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOrigins<sup>9+</sup>
static getOrigins() : Promise
\<
Array
\<
WebStorageOrigin>>
以Promise方式异步获取当前使用Web SQL数据库的所有源的信息。
**返回值:**
| 类型 | 说明 |
| ---------------------------------------- | ---------------------------------------- |
| Promise
<Array
<[
WebStorageOrigin
](
#webstorageorigin9
)
>
> | Promise实例,用于获取当前所有源的信息,信息内容参考WebStorageOrigin。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOrigins
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOrigins
()
.
then
(
origins
=>
{
for
(
let
i
=
0
;
i
<
origins
.
length
;
i
++
)
{
console
.
log
(
'
origin:
'
+
origins
[
i
].
origin
)
console
.
log
(
'
usage:
'
+
origins
[
i
].
usage
)
console
.
log
(
'
quota:
'
+
origins
[
i
].
quota
)
}
})
.
catch
(
error
=>
{
console
.
log
(
'
error:
'
+
error
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOriginQuota<sup>9+</sup>
static getOriginQuota(origin : string, callback : AsyncCallback
\<
number>) : void
使用callback回调异步获取指定源的Web SQL数据库的存储配额,配额以字节为单位。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | --------- |
| origin | string | 是 | 指定源的字符串索引 |
| callback | AsyncCallback
\<
number> | 是 | 指定源的存储配额。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOriginQuota
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOriginQuota
(
this
.
origin
,
(
error
,
quota
)
=>
{
if
(
error
)
{
console
.
log
(
'
error:
'
+
error
)
return
}
console
.
log
(
'
quota:
'
+
quota
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOriginQuota<sup>9+</sup>
static getOriginQuota(origin : string) : Promise
\<
number>
以Promise方式异步获取指定源的Web SQL数据库的存储配额,配额以字节为单位。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- |
| origin | string | 是 | 指定源的字符串索引。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------- |
| Promise
\<
number> | Promise实例,用于获取指定源的存储配额。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOriginQuota
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOriginQuota
(
this
.
origin
)
.
then
(
quota
=>
{
console
.
log
(
'
quota:
'
+
quota
)
})
.
catch
(
error
=>
{
console
.
log
(
'
error:
'
+
error
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOriginUsage<sup>9+</sup>
static getOriginUsage(origin : string, callback : AsyncCallback
\<
number>) : void
以回调方式异步获取指定源的Web SQL数据库的存储量,存储量以字节为单位。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---------- |
| origin | string | 是 | 指定源的字符串索引。 |
| callback | AsyncCallback
\<
number> | 是 | 指定源的存储量。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOriginUsage
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOriginUsage
(
this
.
origin
,
(
error
,
usage
)
=>
{
if
(
error
)
{
console
.
log
(
'
error:
'
+
error
)
return
}
console
.
log
(
'
usage:
'
+
usage
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
### getOriginUsage<sup>9+</sup>
static getOriginUsage(origin : string) : Promise
\<
number>
以Promise方式异步获取指定源的Web SQL数据库的存储量,存储量以字节为单位。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- |
| origin | string | 是 | 指定源的字符串索引。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | ---------------------- |
| Promise
\<
number> | Promise实例,用于获取指定源的存储量。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
origin
"
build
()
{
Column
()
{
Button
(
'
getOriginQuota
'
)
.
onClick
(()
=>
{
web_webview
.
WebStorage
.
getOriginUsage
(
this
.
origin
)
.
then
(
usage
=>
{
console
.
log
(
'
usage:
'
+
usage
)
})
.
catch
(
error
=>
{
console
.
log
(
'
error:
'
+
error
)
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
databaseAccess
(
true
)
}
}
}
```
## WebStorageOrigin<sup>9+</sup>
提供Web SQL数据库的使用信息。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------- |
| origin | string | 是 | 指定源的字符串索引。 |
| usage | number | 是 | 指定源的存储量。 |
| quota | number | 是 | 指定源的存储配额。 |
## MessageLevel枚举说明
| 名称 | 描述 |
| ----- | :---- |
| Debug | 调试级别。 |
| Error | 错误级别。 |
| Info | 消息级别。 |
| Log | 日志级别。 |
| Warn | 警告级别。 |
## RenderExitReason枚举说明
onRenderExited接口返回的渲染进程退出的具体原因。
| 名称 | 描述 |
| -------------------------- | ----------------- |
| ProcessAbnormalTermination | 渲染进程异常退出。 |
| ProcessWasKilled | 收到SIGKILL,或被手动终止。 |
| ProcessCrashed | 渲染进程崩溃退出,如段错误。 |
| ProcessOom | 程序内存不足。 |
| ProcessExitUnknown | 其他原因。 |
## MixedMode枚举说明
| 名称 | 描述 |
| ---------- | ---------------------------------- |
| All | 允许加载HTTP和HTTPS混合内容。所有不安全的内容都可以被加载。 |
| Compatible | 混合内容兼容性模式,部分不安全的内容可能被加载。 |
| None | 不允许加载HTTP和HTTPS混合内容。 |
## CacheMode枚举说明
| 名称 | 描述 |
| ------- | ------------------------------------ |
| Default | 使用未过期的cache加载资源,如果cache中无该资源则从网络中获取。 |
| None | 加载资源使用cache,如果cache中无该资源则从网络中获取。 |
| Online | 加载资源不使用cache,全部从网络中获取。 |
| Only | 只从cache中加载资源。 |
## FileSelectorMode枚举说明
| 名称 | 描述 |
| -------------------- | ---------- |
| FileOpenMode | 打开上传单个文件。 |
| FileOpenMultipleMode | 打开上传多个文件。 |
| FileOpenFolderMode | 打开上传文件夹模式。 |
| FileSaveMode | 文件保存模式。 |
## HitTestType枚举说明
| 名称 | 描述 |
| ------------- | ------------------------ |
| EditText | 可编辑的区域。 |
| Email | 电子邮件地址。 |
| HttpAnchor | 超链接,其src为http。 |
| HttpAnchorImg | 带有超链接的图片,其中超链接的src为http。 |
| Img | HTML::img标签。 |
| Map | 地理地址。 |
| Phone | 电话号码。 |
| Unknown | 未知内容。 |
## SslError<sup>9+</sup>枚举说明
onSslErrorEventReceive接口返回的SSL错误的具体原因。
| 名称 | 描述 |
| ------------ | ----------- |
| Invalid | 一般错误。 |
| HostMismatch | 主机名不匹配。 |
| DateInvalid | 证书日期无效。 |
| Untrusted | 证书颁发机构不受信任。 |
## ProtectedResourceType<sup>9+</sup>枚举说明
| 名称 | 描述 | 备注 |
| --------- | ------------- | -------------------------- |
| MidiSysex | MIDI SYSEX资源。 | 目前仅支持权限事件上报,MIDI设备的使用还未支持。 |
## WebDarkMode<sup>9+</sup>枚举说明
## WebDarkMode<sup>9+</sup>枚举说明
| 名称 | 描述 |
| 名称 | 描述 |
...
@@ -6176,103 +5424,6 @@ onSslErrorEventReceive接口返回的SSL错误的具体原因。
...
@@ -6176,103 +5424,6 @@ onSslErrorEventReceive接口返回的SSL错误的具体原因。
| On | Web深色模式开启。 |
| On | Web深色模式开启。 |
| Auto | Web深色模式跟随系统。 |
| Auto | Web深色模式跟随系统。 |
## WebAsyncController
通过WebAsyncController可以控制Web组件具有异步回调通知的行为,一个WebAsyncController对象控制一个Web组件。
### 创建对象
```
webController: WebController = new WebController();
webAsyncController: WebAsyncController = new WebAsyncController(webController);
```
### storeWebArchive<sup>9+</sup>
storeWebArchive(baseName: string, autoName: boolean, callback: AsyncCallback
<string>
): void
以回调方式异步保存当前页面。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| baseName | string | 是 | 文件存储路径,该值不能为空。
| autoName | boolean | 是 | 决定是否自动生成文件名。
<br/>
如果为false,则将baseName作为文件存储路径。
<br/>
如果为true,则假定baseName是一个目录,将根据当前页的Url自动生成文件名。
| callback | AsyncCallback
<string>
| 是 | 返回文件存储路径,保持网页失败会返回null。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
saveWebArchive
'
)
.
onClick
(()
=>
{
let
webAsyncController
=
new
web_webview
.
WebAsyncController
(
this
.
controller
)
webAsyncController
.
storeWebArchive
(
"
/data/storage/el2/base/
"
,
true
,
(
filename
)
=>
{
if
(
filename
!=
null
)
{
console
.
info
(
`save web archive success:
${
filename
}
`
)
}
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### storeWebArchive<sup>9+</sup>
storeWebArchive(baseName: string, autoName: boolean): Promise
<string>
以Promise方式异步保存当前页面。
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| baseName | string | 是 | 文件存储路径,该值不能为空。
| autoName | boolean | 是 | 决定是否自动生成文件名。
<br/>
如果为false,则将baseName作为文件存储路径。
<br/>
如果为true,则假定baseName是一个目录,将根据当前页的Url自动生成文件名。
**返回值:**
| 类型 | 说明 |
| --------------- | -------------------------------- |
| Promise
<string>
| Promise实例,保存成功返回文件路径,保存失败返回null。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
build
()
{
Column
()
{
Button
(
'
saveWebArchive
'
)
.
onClick
(()
=>
{
let
webAsyncController
=
new
web_webview
.
WebAsyncController
(
this
.
controller
);
webAsyncController
.
storeWebArchive
(
"
/data/storage/el2/base/
"
,
true
)
.
then
(
filename
=>
{
if
(
filename
!=
null
)
{
console
.
info
(
`save web archive success:
${
filename
}
`
)
}
})
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
## WebMessagePort<sup>9+</sup>
## WebMessagePort<sup>9+</sup>
通过WebMessagePort可以进行消息的发送以及接收。
通过WebMessagePort可以进行消息的发送以及接收。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录