Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
73a7325a
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看板
提交
73a7325a
编写于
1月 04, 2023
作者:
Z
zhufenghao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【web】3.2MR需求doc回合monthly_20221018
Signed-off-by:
N
zhufenghao
<
zhufenghao2@huawei.com
>
上级
d85740db
变更
2
展开全部
显示空白变更内容
内联
并排
Showing
2 changed file
with
1154 addition
and
15 deletion
+1154
-15
zh-cn/application-dev/reference/apis/js-apis-webview.md
zh-cn/application-dev/reference/apis/js-apis-webview.md
+446
-12
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+708
-3
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-webview.md
浏览文件 @
73a7325a
...
...
@@ -2338,6 +2338,362 @@ Scroll Test
</html>
```
### getOriginalUrl
getOriginalUrl(): string
获取当前页面的原始url地址。
**系统能力:**
SystemCapability.Web.Webview.Core
**返回值:**
| 类型 | 说明 |
| ------ | ----------------------- |
| string | 当前页面的原始url地址。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
getOrgUrl
'
)
.
onClick
(()
=>
{
try
{
let
url
=
this
.
controller
.
getOriginalUrl
();
console
.
log
(
"
original url:
"
+
url
);
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getFavicon
getFavicon(): image.PixelMap
获取页面的favicon图标。
**系统能力:**
SystemCapability.Web.Webview.Core
**返回值:**
| 类型 | 说明 |
| -------------------------------------- | ------------------------------- |
|
[
PixelMap
](
js-apis-image.md#pixelmap7
)
| 页面favicon图标的PixelMap对象。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
import
image
from
"
@ohos.multimedia.image
"
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
@
State
pixelmap
:
image
.
PixelMap
=
undefined
;
build
()
{
Column
()
{
Button
(
'
getFavicon
'
)
.
onClick
(()
=>
{
try
{
this
.
pixelmap
=
this
.
controller
.
getFavicon
();
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### setNetworkAvailable
setNetworkAvailable(enable: boolean): void
设置JavaScript中的window.navigator.onLine属性。
**系统能力:**
SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | --------------------------------- |
| enable | boolean | 是 | 是否使能window.navigator.onLine。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
setNetworkAvailable
'
)
.
onClick
(()
=>
{
try
{
this
.
controller
.
setNetworkAvailable
(
true
);
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### hasImage
hasImage(callback: AsyncCallback
<boolean>
): void
通过Callback方式异步查找当前页面是否存在图像。
**系统能力:**
SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------- |
| callback | AsyncCallback
\<
boolean> | 是 | 返回查找页面是否存在图像。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web compoent. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
hasImageCb
'
)
.
onClick
(()
=>
{
try
{
this
.
controller
.
hasImage
((
err
,
data
)
=>
{
if
(
error
)
{
console
.
info
(
`hasImage error: `
+
JSON
.
stringify
(
error
))
return
;
}
console
.
info
(
"
hasImage:
"
+
data
);
});
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### hasImage
hasImage(): Promise
<boolean>
通过Promise方式异步查找当前页面是否存在图像。
**系统能力:**
SystemCapability.Web.Webview.Core
**返回值:**
| 类型 | 说明 |
| ----------------- | --------------------------------------- |
| Promise
\<
boolean> | Promise实例,返回查找页面是否存在图像。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web compoent. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
hasImagePm
'
)
.
onClick
(()
=>
{
try
{
this
.
controller
.
hasImage
().
then
((
data
)
=>
{
console
.
info
(
'
hasImage:
'
+
data
);
})
.
catch
(
function
(
error
)
{
console
.
error
(
"
error:
"
+
error
);
})
}
catch
(
error
)
{
console
.
error
(
`Errorcode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### removeCache
removeCache(clearRom: boolean): void
清除应用中的资源缓存文件,此方法将会清除同一应用中所有webview的缓存文件。
**系统能力:**
SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------- | ---- | -------------------------------------------------------- |
| clearRom | boolean | 是 | 设置为true时同时清除rom和ram中的缓存,设置为false时只清除ram中的缓存。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
removeCache
'
)
.
onClick
(()
=>
{
try
{
this
.
controller
.
removeCache
(
false
);
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
### getBackForwardEntries
getBackForwardEntries(): BackForwardList
获取当前Webview的历史信息列表。
**系统能力:**
SystemCapability.Web.Webview.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------- | --------------------------- |
|
[
BackForwardList
](
#backforwardlist
)
| 当前Webview的历史信息列表。 |
**错误码:**
以下错误码的详细介绍请参见
[
webview错误码
](
../errorcodes/errorcode-webview.md
)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
build
()
{
Column
()
{
Button
(
'
getBackForwardEntries
'
)
.
onClick
(()
=>
{
try
{
let
list
=
this
.
controller
.
getBackForwardEntries
()
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
## WebCookieManager
通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookieManager实例。
...
...
@@ -3966,3 +4322,81 @@ Web组件返回的请求/响应头对象。
| origin | string | 是 | 否 | 指定源的字符串索引。 |
| usage | number | 是 | 否 | 指定源的存储量。 |
| quota | number | 是 | 否 | 指定源的存储配额。 |
## BackForwardList
当前Webview的历史信息列表。
**系统能力:**
SystemCapability.Web.Webview.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------ | ------ | ---- | ---- | ---------------------------- |
| currentIndex | number | 是 | 否 | 当前页面在页面历史列表中的索引。 |
| size | number | 是 | 否 | 历史列表中索引的数量。 |
### getItemAtIndex
getItemAtIndex(index: number): HistoryItem
获取历史列表中指定索引的历史记录项信息。
**系统能力:**
SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------- |
| index | number | 是 | 指定历史列表中的索引。 |
**返回值:**
| 类型 | 说明 |
| --------------------------- | ------------ |
|
[
HistoryItem
](
#historyitem
)
| 历史记录项。 |
**示例:**
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
import
image
from
"
@ohos.multimedia.image
"
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
@
State
icon
:
image
.
PixelMap
=
undefined
;
build
()
{
Column
()
{
Button
(
'
getBackForwardEntries
'
)
.
onClick
(()
=>
{
try
{
let
list
=
this
.
controller
.
getBackForwardEntries
();
let
historyItem
=
list
.
getItemAtIndex
(
list
.
currentIndex
);
console
.
log
(
"
HistoryItem:
"
+
JSON
.
stringify
(
historyItem
));
this
.
icon
=
item
.
icon
;
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
}
}
}
```
## HistoryItem
页面历史记录项。
**系统能力:**
SystemCapability.Web.Webview.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------- | -------------------------------------- | ---- | ---- | ---------------------------- |
| icon |
[
PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | 否 | 历史页面图标的PixelMap对象。 |
| historyUrl | string | 是 | 否 | 历史记录项的url地址。 |
| historyRawUrl | string | 是 | 否 | 历史记录项的原始url地址。 |
| title | string | 是 | 否 | 历史记录项的标题。 |
###
\ No newline at end of file
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
73a7325a
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录