Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8bfecf5e
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8bfecf5e
编写于
5月 04, 2023
作者:
L
lixiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add onAlert&onBeforeUnload&onConfirm&onPrompt to load web pages
Signed-off-by:
N
lixiang
<
lixiang380@huawei.com
>
上级
2038f7a0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
99 addition
and
9 deletion
+99
-9
zh-cn/application-dev/reference/apis/js-apis-webview.md
zh-cn/application-dev/reference/apis/js-apis-webview.md
+1
-1
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+98
-8
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-webview.md
浏览文件 @
8bfecf5e
...
...
@@ -4250,7 +4250,7 @@ static saveCookieAsync(callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | :------------------------------------------------- |
| callback | AsyncCallback
\<
void> | 是 |
返回cookie是否成功保存的布尔值作为回调函数的入参
。 |
| callback | AsyncCallback
\<
void> | 是 |
callback回调,用于获取cookie是否成功保存
。 |
**示例:**
...
...
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
8bfecf5e
...
...
@@ -718,8 +718,6 @@ textZoomAtio(textZoomAtio: number)
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
@
Entry
@
Component
struct
WebComponent
{
...
...
@@ -1420,8 +1418,10 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
()
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
xxx.html
"
)
,
controller
:
this
.
controller
})
.
onAlert
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
AlertDialog
.
show
({
title
:
'
onAlert
'
,
message
:
'
text
'
,
...
...
@@ -1448,6 +1448,25 @@ onAlert(callback: (event?: { url: string; message: string; result: JsResult }) =
}
```
```
<!--xxx.html-->
<!DOCTYPE html>
<html>
<head>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
charset=
"utf-8"
>
</head>
<body>
<h1>
WebView onAlert Demo
</h1>
<button
onclick=
"myFunction()"
>
Click here
</button>
<script>
function
myFunction
()
{
alert
(
"
Hello World
"
);
}
</script>
</body>
</html>
```
### onBeforeUnload
onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
...
...
@@ -1481,7 +1500,7 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
xxx.html
"
)
,
controller
:
this
.
controller
})
.
onBeforeUnload
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
...
...
@@ -1511,6 +1530,25 @@ onBeforeUnload(callback: (event?: { url: string; message: string; result: JsResu
}
```
```
<!--xxx.html-->
<!DOCTYPE html>
<html>
<head>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
charset=
"utf-8"
>
</head>
<body
onbeforeunload=
"return myFunction()"
>
<h1>
WebView onBeforeUnload Demo
</h1>
<a
href=
"https://www.example.com"
>
Click here
</a>
<script>
function
myFunction
()
{
return
"
onBeforeUnload Event
"
;
}
</script>
</body>
</html>
```
### onConfirm
onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean)
...
...
@@ -1544,11 +1582,10 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
xxx.html
"
)
,
controller
:
this
.
controller
})
.
onConfirm
((
event
)
=>
{
console
.
log
(
"
event.url:
"
+
event
.
url
)
console
.
log
(
"
event.message:
"
+
event
.
message
)
console
.
log
(
"
event.result:
"
+
event
.
result
)
AlertDialog
.
show
({
title
:
'
onConfirm
'
,
message
:
'
text
'
,
...
...
@@ -1575,6 +1612,34 @@ onConfirm(callback: (event?: { url: string; message: string; result: JsResult })
}
```
```
<!--xxx.html-->
<!DOCTYPE html>
<html>
<head>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
charset=
"utf-8"
>
</head>
<body>
<h1>
WebView onConfirm Demo
</h1>
<button
onclick=
"myFunction()"
>
Click here
</button>
<p
id=
"demo"
></p>
<script>
function
myFunction
()
{
let
x
;
let
r
=
confirm
(
"
click button!
"
);
if
(
r
==
true
)
{
x
=
"
ok
"
;
}
else
{
x
=
"
cancel
"
;
}
document
.
getElementById
(
"
demo
"
).
innerHTML
=
x
;
}
</script>
</body>
</html>
```
### onPrompt<sup>9+</sup>
onPrompt(callback: (event?: { url: string; message: string; value: string; result: JsResult }) => boolean)
...
...
@@ -1606,7 +1671,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
Web
({
src
:
$rawfile
(
"
xxx.html
"
)
,
controller
:
this
.
controller
})
.
onPrompt
((
event
)
=>
{
console
.
log
(
"
url:
"
+
event
.
url
)
console
.
log
(
"
message:
"
+
event
.
message
)
...
...
@@ -1623,7 +1688,7 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
secondaryButton
:
{
value
:
'
ok
'
,
action
:
()
=>
{
event
.
result
.
handle
Confirm
(
)
event
.
result
.
handle
PromptConfirm
(
event
.
value
)
}
},
cancel
:
()
=>
{
...
...
@@ -1637,6 +1702,30 @@ onPrompt(callback: (event?: { url: string; message: string; value: string; resul
}
```
```
<!--xxx.html-->
<!DOCTYPE html>
<html>
<head>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
charset=
"utf-8"
>
</head>
<body>
<h1>
WebView onPrompt Demo
</h1>
<button
onclick=
"myFunction()"
>
Click here
</button>
<p
id=
"demo"
></p>
<script>
function
myFunction
()
{
let
message
=
prompt
(
"
Message info
"
,
"
Hello World
"
);
if
(
message
!=
null
&&
message
!=
""
)
{
document
.
getElementById
(
"
demo
"
).
innerHTML
=
message
;
}
}
</script>
</body>
</html>
```
### onConsole
onConsole(callback: (event?: { message: ConsoleMessage }) => boolean)
...
...
@@ -1690,6 +1779,7 @@ onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisp
| 参数名 | 参数类型 | 参数描述 |
| ------------------ | ------------- | ----------------------------------- |
| url | string | 文件下载的URL。 |
| userAgent | string | 用于下载的用户代理。 |
| contentDisposition | string | 服务器返回的 Content-Disposition响应头,可能为空。 |
| mimetype | string | 服务器返回内容媒体类型(MIME)信息。 |
| contentLength | contentLength | 服务器返回文件的长度。 |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录