Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
81a175d0
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看板
提交
81a175d0
编写于
5月 08, 2023
作者:
L
lixiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Sample code for Customized UserAgent
Signed-off-by:
N
lixiang
<
lixiang380@huawei.com
>
上级
effdc6de
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
72 addition
and
41 deletion
+72
-41
zh-cn/application-dev/reference/apis/js-apis-webview.md
zh-cn/application-dev/reference/apis/js-apis-webview.md
+71
-40
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
...ication-dev/reference/arkui-ts/ts-basic-components-web.md
+1
-1
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-webview.md
浏览文件 @
81a175d0
...
...
@@ -234,7 +234,7 @@ postMessageEventExt(message: WebMessageExt): void
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | :------------- |
| message |
[
WebMessageExt
](
#webmessageext
)
| 是 | 要发送的消息。 |
| message |
[
WebMessageExt
](
#webmessageext
10
)
| 是 | 要发送的消息。 |
**错误码:**
...
...
@@ -491,7 +491,7 @@ static setHttpDns(secureDnsMode:SecureDnsMode, secureDnsConfig:string): void
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | ------------- |
| secureDnsMode |
[
SecureDnsMode
](
#securednsmode
)
| 是 | 使用HTTPDNS的模式。|
| secureDnsMode |
[
SecureDnsMode
](
#securednsmode
10
)
| 是 | 使用HTTPDNS的模式。|
| secureDnsConfig | string | 是 | HTTPDNS server的配置,必须是https协议并且只允许配置一个server。 |
**示例:**
...
...
@@ -2137,24 +2137,24 @@ struct WebComponent {
this
.
ports
=
this
.
controller
.
createWebMessagePorts
();
// 2、在应用侧的消息端口(如端口1)上注册回调事件。
this
.
ports
[
1
].
onMessageEvent
((
result
:
web_webview
.
WebMessage
)
=>
{
let
msg
=
'
Got msg from HTML:
'
;
if
(
typeof
(
result
)
==
"
string
"
)
{
console
.
log
(
"
received string message from html5, string is:
"
+
result
);
msg
=
msg
+
result
;
}
else
if
(
typeof
(
result
)
==
"
object
"
)
{
if
(
result
instanceof
ArrayBuffer
)
{
console
.
log
(
"
received arraybuffer from html5, length is:
"
+
result
.
byteLength
);
msg
=
msg
+
"
lenght is
"
+
result
.
byteLength
;
}
else
{
console
.
log
(
"
not support
"
);
}
let
msg
=
'
Got msg from HTML:
'
;
if
(
typeof
(
result
)
==
"
string
"
)
{
console
.
log
(
"
received string message from html5, string is:
"
+
result
);
msg
=
msg
+
result
;
}
else
if
(
typeof
(
result
)
==
"
object
"
)
{
if
(
result
instanceof
ArrayBuffer
)
{
console
.
log
(
"
received arraybuffer from html5, length is:
"
+
result
.
byteLength
);
msg
=
msg
+
"
lenght is
"
+
result
.
byteLength
;
}
else
{
console
.
log
(
"
not support
"
);
}
this
.
receivedFromHtml
=
msg
;
})
// 3、将另一个消息端口(如端口0)发送到HTML侧,由HTML侧保存并使用。
this
.
controller
.
postMessage
(
'
__init_port__
'
,
[
this
.
ports
[
0
]],
'
*
'
);
}
else
{
console
.
log
(
"
not support
"
);
}
this
.
receivedFromHtml
=
msg
;
})
// 3、将另一个消息端口(如端口0)发送到HTML侧,由HTML侧保存并使用。
this
.
controller
.
postMessage
(
'
__init_port__
'
,
[
this
.
ports
[
0
]],
'
*
'
);
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
...
...
@@ -2523,6 +2523,37 @@ struct WebComponent {
}
```
支持开发者基于默认的UserAgent去定制UserAgent。
```
ts
// xxx.ets
import
web_webview
from
'
@ohos.web.webview
'
;
@
Entry
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
@
State
ua
:
string
=
""
aboutToAppear
():
void
{
web_webview
.
once
(
'
webInited
'
,
()
=>
{
try
{
// 应用侧用法示例,定制UserAgent。
this
.
ua
=
this
.
controller
.
getUserAgent
()
+
'
xxx
'
;
}
catch
(
error
)
{
console
.
error
(
`ErrorCode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
})
}
build
()
{
Column
()
{
Web
({
src
:
'
www.example.com
'
,
controller
:
this
.
controller
})
.
userAgent
(
this
.
ua
)
}
}
}
```
### getTitle
getTitle(): string
...
...
@@ -3191,7 +3222,7 @@ import image from "@ohos.multimedia.image"
@
Component
struct
WebComponent
{
controller
:
web_webview
.
WebviewController
=
new
web_webview
.
WebviewController
();
@
State
pixelmap
:
image
.
PixelMap
=
undefined
;
@
State
pixelmap
:
image
.
PixelMap
=
undefined
;
build
()
{
Column
()
{
...
...
@@ -3297,12 +3328,12 @@ struct WebComponent {
.
onClick
(()
=>
{
try
{
this
.
controller
.
hasImage
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
info
(
`hasImage error: `
+
JSON
.
stringify
(
error
))
return
;
}
console
.
info
(
"
hasImage:
"
+
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
}
`
);
}
...
...
@@ -3352,11 +3383,11 @@ struct WebComponent {
.
onClick
(()
=>
{
try
{
this
.
controller
.
hasImage
().
then
((
data
)
=>
{
console
.
info
(
'
hasImage:
'
+
data
);
})
.
catch
(
function
(
error
)
{
console
.
error
(
"
error:
"
+
error
);
})
console
.
info
(
'
hasImage:
'
+
data
);
})
.
catch
(
function
(
error
)
{
console
.
error
(
"
error:
"
+
error
);
})
}
catch
(
error
)
{
console
.
error
(
`Errorcode:
${
error
.
code
}
, Message:
${
error
.
message
}
`
);
}
...
...
@@ -4131,7 +4162,7 @@ struct WebComponent {
通过WebCookie可以控制Web组件中的cookie的各种行为,其中每个应用中的所有web组件共享一个WebCookieManager实例。
###
getCookie
### getCookie
static getCookie(url: string): string
...
...
@@ -4187,7 +4218,7 @@ struct WebComponent {
}
```
###
setCookie
### setCookie
static setCookie(url: string, value: string): void
...
...
@@ -4238,7 +4269,7 @@ struct WebComponent {
}
```
###
saveCookieAsync
### saveCookieAsync
static saveCookieAsync(callback: AsyncCallback
\<
void>): void
...
...
@@ -4284,7 +4315,7 @@ struct WebComponent {
}
```
###
saveCookieAsync
### saveCookieAsync
static saveCookieAsync(): Promise
\<
void>
...
...
@@ -4331,7 +4362,7 @@ struct WebComponent {
}
```
###
putAcceptCookieEnabled
### putAcceptCookieEnabled
static putAcceptCookieEnabled(accept: boolean): void
...
...
@@ -4372,7 +4403,7 @@ struct WebComponent {
}
```
###
isCookieAllowed
### isCookieAllowed
static isCookieAllowed(): boolean
...
...
@@ -4410,7 +4441,7 @@ struct WebComponent {
}
```
###
putAcceptThirdPartyCookieEnabled
### putAcceptThirdPartyCookieEnabled
static putAcceptThirdPartyCookieEnabled(accept: boolean): void
...
...
@@ -4451,7 +4482,7 @@ struct WebComponent {
}
```
###
isThirdPartyCookieAllowed
### isThirdPartyCookieAllowed
static isThirdPartyCookieAllowed(): boolean
...
...
@@ -4489,7 +4520,7 @@ struct WebComponent {
}
```
###
existCookie
### existCookie
static existCookie(): boolean
...
...
@@ -4527,7 +4558,7 @@ struct WebComponent {
}
```
###
deleteEntireCookie
### deleteEntireCookie
static deleteEntireCookie(): void
...
...
@@ -4558,7 +4589,7 @@ struct WebComponent {
}
```
###
deleteSessionCookie
### deleteSessionCookie
static deleteSessionCookie(): void
...
...
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md
浏览文件 @
81a175d0
...
...
@@ -4328,7 +4328,7 @@ resend(): void
}
```
###
cancel<sup>9+</sup>
### cancel<sup>9+</sup>
cancel(): void
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录