Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
98b9dfd8
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
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看板
未验证
提交
98b9dfd8
编写于
6月 08, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 08, 2023
浏览文件
操作
浏览文件
下载
差异文件
!19395 modify web docs for descriptions sample code(3.2release)
Merge pull request !19395 from 李想/OpenHarmony-3.2-Release
上级
409b0c94
19576043
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
98 addition
and
38 deletion
+98
-38
zh-cn/application-dev/reference/apis/js-apis-webview.md
zh-cn/application-dev/reference/apis/js-apis-webview.md
+70
-11
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+28
-27
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-webview.md
浏览文件 @
98b9dfd8
...
...
@@ -213,7 +213,7 @@ struct WebComponent {
Button
(
'
close
'
)
.
onClick
(()
=>
{
try
{
if
(
this
.
msgPort
&&
this
.
msgPort
[
1
]
)
{
if
(
this
.
msgPort
&&
this
.
msgPort
.
length
==
2
)
{
this
.
msgPort
[
1
].
close
();
}
else
{
console
.
error
(
"
msgPort is null, Please initialize first
"
);
...
...
@@ -394,7 +394,7 @@ struct WebComponent {
.
onClick
(()
=>
{
try
{
// 需要加载的URL是Resource类型。
this
.
controller
.
loadUrl
(
$rawfile
(
'
xx
x.html
'
));
this
.
controller
.
loadUrl
(
$rawfile
(
'
inde
x.html
'
));
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
...
...
@@ -407,8 +407,9 @@ struct WebComponent {
2.
加载沙箱路径下的本地资源文件,可以参考
[
web
](
../arkui-ts/ts-basic-components-web.md#web
)
加载沙箱路径的示例代码。
加载的html文件。
```
html
<!--
xx
x.html -->
<!--
inde
x.html -->
<!DOCTYPE html>
<html>
<body>
...
...
@@ -1034,6 +1035,24 @@ struct Index {
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta
charset=
"utf-8"
>
<body>
Hello world!
</body>
<script
type=
"text/javascript"
>
function
htmlTest
()
{
str
=
objName
.
test
(
"
test function
"
)
console
.
log
(
'
objName.test result:
'
+
str
)
}
</script>
</html>
```
### runJavaScript
runJavaScript(script: string, callback : AsyncCallback
\<
string>): void
...
...
@@ -1097,6 +1116,24 @@ struct WebComponent {
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta
charset=
"utf-8"
>
<body>
Hello world!
</body>
<script
type=
"text/javascript"
>
function
test
()
{
console
.
log
(
'
Ark WebComponent
'
)
return
"
This value is from index.html
"
}
</script>
</html>
```
### runJavaScript
runJavaScript(script: string): Promise
\<
string>
...
...
@@ -1161,6 +1198,24 @@ struct WebComponent {
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
<html>
<meta
charset=
"utf-8"
>
<body>
Hello world!
</body>
<script
type=
"text/javascript"
>
function
test
()
{
console
.
log
(
'
Ark WebComponent
'
)
return
"
This value is from index.html
"
}
</script>
</html>
```
### deleteJavaScriptRegister
deleteJavaScriptRegister(name: string): void
...
...
@@ -1637,14 +1692,15 @@ struct WebComponent {
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
$rawfile
(
'
xx
x.html
'
),
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
inde
x.html
'
),
controller
:
this
.
controller
})
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -2432,14 +2488,15 @@ struct WebComponent {
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
index.html
'
)
,
controller
:
this
.
controller
})
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -2504,14 +2561,15 @@ struct WebComponent {
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
index.html
'
)
,
controller
:
this
.
controller
})
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -2576,14 +2634,15 @@ struct WebComponent {
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
index.html
'
)
,
controller
:
this
.
controller
})
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
98b9dfd8
...
...
@@ -72,7 +72,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
let
url
=
'
file://
'
+
globalThis
.
filesDir
+
'
/
xx
x.html
'
let
url
=
'
file://
'
+
globalThis
.
filesDir
+
'
/
inde
x.html
'
@
Entry
@
Component
...
...
@@ -103,6 +103,7 @@ Web(options: { src: ResourceStr, controller: WebviewController | WebController})
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
...
...
@@ -567,15 +568,16 @@ horizontalScrollBarAccess(horizontalScrollBar: boolean)
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
()
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
index.html
'
)
,
controller
:
this
.
controller
})
.
horizontalScrollBarAccess
(
true
)
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -620,15 +622,16 @@ verticalScrollBarAccess(verticalScrollBar: boolean)
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
()
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
'
index.html
'
)
,
controller
:
this
.
controller
})
.
verticalScrollBarAccess
(
true
)
}
}
}
```
加载的html文件。
```
html
<!--
xx
x.html-->
<!--
inde
x.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -1281,7 +1284,7 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
()
build
()
{
Column
()
{
Web
({
src
:
$rawfile
(
"
xx
x.html
"
),
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
inde
x.html
"
),
controller
:
this
.
controller
})
.
onAlert
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
...
...
@@ -1311,8 +1314,9 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
}
```
```
<!--xxx.html-->
加载的html文件。
```
html
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -1363,7 +1367,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
build
()
{
Column
()
{
Web
({
src
:
$rawfile
(
"
xx
x.html
"
),
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
inde
x.html
"
),
controller
:
this
.
controller
})
.
onBeforeUnload
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
...
...
@@ -1393,8 +1397,9 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
}
```
```
<!--xxx.html-->
加载的html文件。
```
html
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -1445,7 +1450,7 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
build
()
{
Column
()
{
Web
({
src
:
$rawfile
(
"
xx
x.html
"
),
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
inde
x.html
"
),
controller
:
this
.
controller
})
.
onConfirm
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
...
...
@@ -1475,8 +1480,9 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
}
```
```
<!--xxx.html-->
加载的html文件。
```
html
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -1534,7 +1540,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
build
()
{
Column
()
{
Web
({
src
:
$rawfile
(
"
xx
x.html
"
),
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
inde
x.html
"
),
controller
:
this
.
controller
})
.
onPrompt
((
event
)
=>
{
console
.
log
(
"
url:
"
+
event
.
url
)
console
.
log
(
"
message:
"
+
event
.
message
)
...
...
@@ -1565,8 +1571,9 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
}
```
```
<!--xxx.html-->
加载的html文件。
```
html
<!--index.html-->
<!DOCTYPE html>
<html>
<head>
...
...
@@ -4559,6 +4566,7 @@ registerJavaScriptProxy(options: { object: object, name: string, methodList: Arr
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
...
...
@@ -4620,6 +4628,7 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
}
```
加载的html文件。
```
html
<!-- index.html -->
<!DOCTYPE html>
...
...
@@ -4635,7 +4644,6 @@ runJavaScript(options: { script: string, callback?: (result: string) => void })
}
</script>
</html>
```
### stop<sup>(deprecated)</sup>
...
...
@@ -4701,18 +4709,11 @@ clearHistory(): void
通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookie。通过controller方法中的getCookieManager方法可以获取WebCookie对象,进行后续的cookie管理操作。
### setCookie<sup>(deprecated)</sup>
setCookie(
url: string, value: string
): boolean
setCookie(): boolean
设置cookie,该方法为同步方法。设置成功返回true,否则返回false。
从API version 9开始不再维护,建议使用
[
setCookie<sup>9+</sup>
](
../apis/js-apis-webview.md#setcookie
)
代替。
**参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----- | ------ | ---- | ---- | ----------------- |
| url | string | 是 | - | 要设置的cookie所属的url,建议使用完整的url。 |
| value | string | 是 | - | cookie的值。 |
**返回值:**
| 类型 | 说明 |
...
...
@@ -4732,7 +4733,7 @@ setCookie(url: string, value: string): boolean
Column
()
{
Button
(
'
setCookie
'
)
.
onClick
(()
=>
{
let
result
=
this
.
controller
.
getCookieManager
().
setCookie
(
"
https://www.example.com
"
,
"
a=b
"
)
let
result
=
this
.
controller
.
getCookieManager
().
setCookie
()
console
.
log
(
"
result:
"
+
result
)
})
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录