Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c8911e98
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看板
未验证
提交
c8911e98
编写于
1月 10, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 10, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13380 修复资料web.d.ts资料不对应及接口废弃描述补充(月度)
Merge pull request !13380 from Ted/monthly_20221018
上级
64791ad4
7aad534b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
58 addition
and
809 deletion
+58
-809
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+58
-809
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
c8911e98
...
...
@@ -1761,7 +1761,7 @@ onRefreshAccessedHistory(callback: (event?: { url: string, isRefreshed: boolean
}
```
### onRenderExited
### onRenderExited
<sup>9+</sup>
onRenderExited(callback: (event?: { renderExitReason: RenderExitReason }) => void)
...
...
@@ -3537,24 +3537,28 @@ invoke(origin: string, allow: boolean, retain: boolean): void
| ------ | ------- | ---- | ---- | ---------------------------------------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
| allow | boolean | 是 | - | 设置的地理位置权限状态。 |
| retain | boolean | 是 | - | 是否允许将地理位置权限状态保存到系统中。可通过
[
GeolocationPermissions
](
#geolocationpermissions9
)
接口管理保存到系统的地理位置权限。 |
| retain | boolean | 是 | - | 是否允许将地理位置权限状态保存到系统中。可通过
[
GeolocationPermissions
<sup>9+</sup>
](
../apis/js-apis-webview.md#geolocationpermissions
)
接口管理保存到系统的地理位置权限。 |
## 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()
```
### requestFocus
### requestFocus
<sup>(deprecated)</sup>
requestFocus()
使当前web页面获取焦点。
从API version 9开始不再维护,建议使用
[
requestFocus<sup>9+</sup>
](
../apis/js-apis-webview.md#requestfocus
)
代替。
**示例:**
```
ts
...
...
@@ -3576,12 +3580,14 @@ requestFocus()
}
```
### accessBackward
### accessBackward
<sup>(deprecated)</sup>
accessBackward(): boolean
当前页面是否可后退,即当前页面是否有返回历史记录。
从API version 9开始不再维护,建议使用
[
accessBackward<sup>9+</sup>
](
../apis/js-apis-webview.md#accessbackward
)
代替。
**返回值:**
| 类型 | 说明 |
...
...
@@ -3610,12 +3616,14 @@ accessBackward(): boolean
}
```
### accessForward
### accessForward
<sup>(deprecated)</sup>
accessForward(): boolean
当前页面是否可前进,即当前页面是否有前进历史记录。
从API version 9开始不再维护,建议使用
[
accessForward<sup>9+</sup>
](
../apis/js-apis-webview.md#accessforward
)
代替。
**返回值:**
| 类型 | 说明 |
...
...
@@ -3644,12 +3652,14 @@ accessForward(): boolean
}
```
### accessStep
### accessStep
<sup>(deprecated)</sup>
accessStep(step: number): boolean
当前页面是否可前进或者后退给定的step步。
从API version 9开始不再维护,建议使用
[
accessStep<sup>9+</sup>
](
../apis/js-apis-webview.md#accessstep
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -3685,12 +3695,14 @@ accessStep(step: number): boolean
}
```
### backward
### backward
<sup>(deprecated)</sup>
backward(): void
按照历史栈,后退一个页面。一般结合accessBackward一起使用。
从API version 9开始不再维护,建议使用
[
backward<sup>9+</sup>
](
../apis/js-apis-webview.md#backward
)
代替。
**示例:**
```
ts
...
...
@@ -3712,12 +3724,14 @@ backward(): void
}
```
### forward
### forward
<sup>(deprecated)</sup>
forward(): void
按照历史栈,前进一个页面。一般结合accessForward一起使用。
从API version 9开始不再维护,建议使用
[
forward<sup>9+</sup>
](
../apis/js-apis-webview.md#forward
)
代替。
**示例:**
```
ts
...
...
@@ -3773,12 +3787,14 @@ backOrForward(step: number): void
}
```
### deleteJavaScriptRegister
### deleteJavaScriptRegister
<sup>(deprecated)</sup>
deleteJavaScriptRegister(name: string)
删除通过registerJavaScriptProxy注册到window上的指定name的应用侧JavaScript对象。删除后立即生效,无须调用
[
refresh
](
#refresh
)
接口。
从API version 9开始不再维护,建议使用
[
deleteJavaScriptRegister<sup>9+</sup>
](
../apis/js-apis-webview.md#deletejavascriptregister
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -3807,12 +3823,14 @@ deleteJavaScriptRegister(name: string)
}
```
### getHitTest
### getHitTest
<sup>(deprecated)</sup>
getHitTest(): HitTestType
获取当前被点击区域的元素类型。
从API version 9开始不再维护,建议使用
[
getHitTest<sup>9+</sup>
](
../apis/js-apis-webview.md#gethittest
)
代替。
**返回值:**
| 类型 | 说明 |
...
...
@@ -4007,7 +4025,7 @@ getDefaultUserAgent(): string
}
```
### loadData
### loadData
<sup>(deprecated)</sup>
loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string })
...
...
@@ -4017,6 +4035,8 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
当baseUrl为“http/https"协议时,编码后的data字符串将被Web组件以类似loadUrl的方式以非编码字符串处理。
从API version 9开始不再维护,建议使用
[
loadData<sup>9+</sup>
](
../apis/js-apis-webview.md#loaddata
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -4052,7 +4072,7 @@ baseUrl为空时,通过”data“协议加载指定的一段字符串。
}
```
### loadUrl
### loadUrl
<sup>(deprecated)</sup>
loadUrl(options: { url: string | Resource, headers?: Array
\<
Header
\>
})
...
...
@@ -4062,6 +4082,8 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
而通过registerJavaScriptProxy注入的对象,在loadUrl导航到新的页面也会有效。
从API version 9开始不再维护,建议使用
[
loadUrl<sup>9+</sup>
](
../apis/js-apis-webview.md#loadurl
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -4090,12 +4112,14 @@ loadUrl(options: { url: string | Resource, headers?: Array\<Header\> })
}
```
### onActive
### onActive
<sup>(deprecated)</sup>
onActive(): void
调用此接口通知Web组件进入前台激活状态。
从API version 9开始不再维护,建议使用
[
onActive<sup>9+</sup>
](
../apis/js-apis-webview.md#onactive
)
代替。
**示例:**
```
ts
...
...
@@ -4117,12 +4141,14 @@ onActive(): void
}
```
### onInactive
### onInactive
<sup>(deprecated)</sup>
onInactive(): void
调用此接口通知Web组件进入未激活状态。
从API version 9开始不再维护,建议使用
[
onInactive<sup>9+</sup>
](
../apis/js-apis-webview.md#oninactive
)
代替。
**示例:**
```
ts
...
...
@@ -4144,11 +4170,13 @@ onInactive(): void
}
```
### zoom
### zoom
<sup>(deprecated)</sup>
zoom(factor: number): void
调整当前网页的缩放比例。
从API version 9开始不再维护,建议使用
[
zoom<sup>9+</sup>
](
../apis/js-apis-webview.md#zoom
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 参数描述 |
...
...
@@ -4243,12 +4271,14 @@ zoomOut(): boolean
}
```
### refresh
### refresh
<sup>(deprecated)</sup>
refresh()
调用此接口通知Web组件刷新网页。
从API version 9开始不再维护,建议使用
[
refresh<sup>9+</sup>
](
../apis/js-apis-webview.md#refresh
)
代替。
**示例:**
```
ts
...
...
@@ -4270,12 +4300,14 @@ refresh()
}
```
### registerJavaScriptProxy
### registerJavaScriptProxy
<sup>(deprecated)</sup>
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array
\<
string
\>
})
注入JavaScript对象到window对象中,并在window对象中调用该对象的方法。注册后,须调用
[
refresh
](
#refresh
)
接口生效。
从API version 9开始不再维护,建议使用
[
registerJavaScriptProxy<sup>9+</sup>
](
../apis/js-apis-webview.md#registerjavascriptproxy
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -4336,12 +4368,14 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
```
### runJavaScript
### runJavaScript
<sup>(deprecated)</sup>
runJavaScript(options: { script: string, callback?: (result: string) => void })
异步执行JavaScript脚本,并通过回调方式返回脚本执行的结果。runJavaScript需要在loadUrl完成后,比如onPageEnd中调用。
从API version 9开始不再维护,建议使用
[
runJavaScript<sup>9+</sup>
](
../apis/js-apis-webview.md#runjavascript
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
...
...
@@ -4395,12 +4429,14 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
```
### stop
### stop
<sup>(deprecated)</sup>
stop()
停止页面加载。
从API version 9开始不再维护,建议使用
[
stop<sup>9+</sup>
](
../apis/js-apis-webview.md#stop
)
代替。
**示例:**
```
ts
...
...
@@ -4422,12 +4458,14 @@ stop()
}
```
### clearHistory
### clearHistory
<sup>(deprecated)</sup>
clearHistory(): void
删除所有前进后退记录。
从API version 9开始不再维护,建议使用
[
clearHistory<sup>9+</sup>
](
../apis/js-apis-webview.md#clearhistory
)
代替。
**示例:**
```
ts
...
...
@@ -4891,39 +4929,6 @@ setCookie(url: string, value: string): boolean
}
```
### saveCookieSync<sup>9+</sup>
saveCookieSync(): boolean
将当前存在内存中的cookie同步到磁盘中,该方法为同步方法。
**返回值:**
| 类型 | 说明 |
| ------- | -------------------- |
| boolean | 同步内存cookie到磁盘操作是否成功。 |
**示例:**
```
ts
// xxx.ets
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
()
build
()
{
Column
()
{
Button
(
'
saveCookieSync
'
)
.
onClick
(()
=>
{
let
result
=
this
.
controller
.
getCookieManager
().
saveCookieSync
()
console
.
log
(
"
result:
"
+
result
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getCookie<sup>9+</sup>
getCookie(url: string): string
...
...
@@ -5335,762 +5340,6 @@ deleteSessionCookie(): void
}
```
## WebDataBase<sup>9+</sup>
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>
web组件地理位置权限管理对象。
### allowGeolocation<sup>9+</sup>
static allowGeolocation(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
=
"
file:///
"
build
()
{
Column
()
{
Button
(
'
allowGeolocation
'
)
.
onClick
(()
=>
{
web_webview
.
GeolocationPermissions
.
allowGeolocation
(
this
.
origin
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### deleteGeolocation<sup>9+</sup>
static deleteGeolocation(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
=
"
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枚举说明
| 名称 | 描述 |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录