未验证 提交 13e00f83 编写于 作者: O openharmony_ci 提交者: Gitee

!17965 add Sample code for Customized UserAgent

Merge pull request !17965 from 李想/master
......@@ -234,7 +234,7 @@ postMessageEventExt(message: WebMessageExt): void
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | :------------- |
| message | [WebMessageExt](#webmessageext) | 是 | 要发送的消息。 |
| message | [WebMessageExt](#webmessageext10) | 是 | 要发送的消息。 |
**错误码:**
......@@ -491,7 +491,7 @@ static setHttpDns(secureDnsMode:SecureDnsMode, secureDnsConfig:string): void
| 参数名 | 类型 | 必填 | 说明 |
| ------------------ | ------- | ---- | ------------- |
| secureDnsMode | [SecureDnsMode](#securednsmode) | 是 | 使用HTTPDNS的模式。|
| secureDnsMode | [SecureDnsMode](#securednsmode10) | 是 | 使用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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册