Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
0219125d
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
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看板
未验证
提交
0219125d
编写于
9月 05, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 05, 2022
浏览文件
操作
浏览文件
下载
差异文件
!8234 web新增GeolocationPermissions napi
Merge pull request !8234 from xiongjun_gitee/master
上级
957ee78f
cfda9f88
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
331 addition
and
0 deletion
+331
-0
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+331
-0
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
0219125d
...
@@ -1298,6 +1298,51 @@ onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebCo
...
@@ -1298,6 +1298,51 @@ onContextMenuShow(callback: (event?: { param: WebContextMenuParam, result: WebCo
}
}
```
```
### onGeolocationShow
onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocation }) => void)
通知用户收到地理位置信息获取请求。
**参数:**
| 参数名 | 参数类型 | 参数描述 |
| ----------- | ------------------------------- | ---------------- |
| origin | string | 指定源的字符串索引。 |
| geolocation |
[
JsGeolocation
](
#jsgeolocation
)
| 通知Web组件用户操作行为。|
**示例:**
```
ts
// xxx.ets
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
geolocationAccess
(
true
)
.
onGeolocationShow
((
event
)
=>
{
AlertDialog
.
show
({
title
:
'
title
'
,
message
:
'
text
'
,
confirm
:
{
value
:
'
onConfirm
'
,
action
:
()
=>
{
event
.
geolocation
.
invoke
(
event
.
origin
,
true
,
true
);
}
},
cancel
:
()
=>
{
event
.
geolocation
.
invoke
(
event
.
origin
,
false
,
true
);
}
})
})
}
}
}
```
## ConsoleMessage
## ConsoleMessage
Web组件获取控制台信息对象。示例代码参考
[
onConsole事件
](
#onconsole
)
。
Web组件获取控制台信息对象。示例代码参考
[
onConsole事件
](
#onconsole
)
。
...
@@ -1844,6 +1889,24 @@ copyImage(): void
...
@@ -1844,6 +1889,24 @@ copyImage(): void
WebContextMenuParam有图片内容则复制图片。
WebContextMenuParam有图片内容则复制图片。
## JsGeolocation
Web组件返回授权或拒绝权限功能的对象。示例代码参考
[
onGeolocationShow事件
](
#ongeolocationshow
)
。
### invoke
invoke(origin: string, allow: boolean, retain: boolean): void
设置网页地理位置权限状态。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| --------- | ------- | ---- | ----- | ---------------------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
| allow | boolean | 是 | - | 设置的地理位置权限状态。 |
| retain | boolean | 是 | - | 是否允许将地理位置权限状态保存到系统中。可通过
[
GeolocationPermissions
](
#geolocationpermissions9
)
接口管理保存到系统的地理位置权限。 |
## WebController
## WebController
通过WebController可以控制Web组件各种行为。一个WebController对象只能控制一个Web组件,且必须在Web组件和WebController绑定后,才能调用WebController上的方法。
通过WebController可以控制Web组件各种行为。一个WebController对象只能控制一个Web组件,且必须在Web组件和WebController绑定后,才能调用WebController上的方法。
...
@@ -3059,6 +3122,274 @@ static saveHttpAuthCredentials(host: string, realm: string, username: string, pa
...
@@ -3059,6 +3122,274 @@ static saveHttpAuthCredentials(host: string, realm: string, username: string, pa
}
}
```
```
## GeolocationPermissions<sup>9+</sup>
web组件地理位置权限管理对象。
### allowGeolocation<sup>9+</sup>
static allowGeolocation(origin: string): void
允许指定来源使用地理位置接口。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | ---- | ----- | ------------- |
| origin | string | 是 | - | 指定源的字符串索引。 |
**示例:**
```
ts
// xxx.ets
import
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
file:///
"
;
build
()
{
Column
()
{
Button
(
'
allowGeolocation
'
)
.
onClick
(()
=>
{
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
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
file:///
"
;
build
()
{
Column
()
{
Button
(
'
deleteGeolocation
'
)
.
onClick
(()
=>
{
webview
.
GeolocationPermissions
.
deleteGeolocation
(
this
.
origin
);
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### deleteAllGeolocation<sup>9+</sup>
static deleteAllGeolocation(): void
清除所有来源的地理位置权限状态。
**示例:**
```
ts
// xxx.ets
import
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
build
()
{
Column
()
{
Button
(
'
deleteAllGeolocation
'
)
.
onClick
(()
=>
{
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
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
file:///
"
;
build
()
{
Column
()
{
Button
(
'
getAccessibleGeolocationAsync
'
)
.
onClick
(()
=>
{
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
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
origin
:
string
=
"
file:///
"
;
build
()
{
Column
()
{
Button
(
'
getAccessibleGeolocationPromise
'
)
.
onClick
(()
=>
{
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
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
build
()
{
Column
()
{
Button
(
'
getStoredGeolocationAsync
'
)
.
onClick
(()
=>
{
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
webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
WebController
=
new
WebController
();
build
()
{
Column
()
{
Button
(
'
getStoredGeolocationPromise
'
)
.
onClick
(()
=>
{
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<sup>9+</sup>
通过WebStorage可管理Web SQL数据库接口和HTML5 Web存储接口,每个应用中的所有Web组件共享一个WebStorage。
通过WebStorage可管理Web SQL数据库接口和HTML5 Web存储接口,每个应用中的所有Web组件共享一个WebStorage。
### deleteAllData<sup>9+</sup>
### deleteAllData<sup>9+</sup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录