未验证 提交 8984c99c 编写于 作者: O openharmony_ci 提交者: Gitee

!14831 web资料中接口accessForward和postMessage修改(月度)

Merge pull request !14831 from 李想/monthly_20221018
......@@ -20,7 +20,7 @@
import web_webview from '@ohos.web.webview';
```
### once
## once
once(type: string, callback: Callback\<void\>): void
......@@ -43,7 +43,7 @@ import web_webview from '@ohos.web.webview'
web_webview.once("webInited", () => {
console.log("setCookie")
web_webview.WebCookieManager.setCookie("www.example.com", "a=b")
web_webview.WebCookieManager.setCookie("https://www.example.com", "a=b")
})
@Entry
......@@ -338,7 +338,6 @@ struct WebComponent {
}
})
Web({ src: 'www.example.com', controller: this.controller })
.webDebuggingAccess(true)
}
}
}
......@@ -438,7 +437,34 @@ struct WebComponent {
}
```
### accessforward
加载本地资源
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
updataContent: string = '<body><div><image src=file:///data/storage/el1/bundle/entry/resources/rawfile/xxx.png alt="image -- end" width="500" height="250"></image></div></body>'
build() {
Column() {
Button('loadData')
.onClick(() => {
try {
this.controller.loadData(this.updataContent, "text/html", "UTF-8", " ", " ");
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### accessForward
accessForward(): boolean
......@@ -1565,7 +1591,7 @@ struct WebComponent {
.onClick(() => {
try {
if (this.ports && this.ports[1]) {
this.ports[1].postMessageEvent("this.sendFromEts");
this.ports[1].postMessageEvent(this.sendFromEts);
} else {
console.error(`ports is null, Please initialize first`);
}
......@@ -3174,7 +3200,7 @@ struct WebComponent {
Button('getCookie')
.onClick(() => {
try {
let value = web_webview.WebCookieManager.getCookie('www.example.com');
let value = web_webview.WebCookieManager.getCookie('https://www.example.com');
console.log("value: " + value);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
......@@ -3226,7 +3252,7 @@ struct WebComponent {
Button('setCookie')
.onClick(() => {
try {
web_webview.WebCookieManager.setCookie('www.example.com', 'a=b');
web_webview.WebCookieManager.setCookie('https://www.example.com', 'a=b');
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
......@@ -4094,9 +4120,6 @@ struct WebComponent {
try {
this.username_password = web_webview.WebDataBase.getHttpAuthCredentials(this.host, this.realm);
console.log('num: ' + this.username_password.length);
ForEach(this.username_password, (item) => {
console.log('username_password: ' + item);
}, item => item)
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
......
......@@ -16,7 +16,7 @@
## 接口
Web(options: { src: ResourceStr, controller: WebController | WebviewController})
Web(options: { src: ResourceStr, controller: WebviewController | WebController})
> **说明:**
>
......@@ -28,26 +28,13 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ---------- | ---------------------------------------- | ---- | ------- |
| src | [ResourceStr](ts-types.md) | 是 | 网页资源地址。 |
| controller | [WebController](#webcontroller) \| [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) | 是 | 控制器。 |
| controller | [WebviewController<sup>9+</sup>](../apis/js-apis-webview.md#webviewcontroller) \| [WebController](#webcontroller) | 是 | 控制器。从API Version 9开始,WebController不在维护,建议使用WebviewController替代。 |
**示例:**
加载在线网页
```ts
// xxx.ets
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
......@@ -65,10 +52,12 @@ Web(options: { src: ResourceStr, controller: WebController | WebviewController})
加载本地网页
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src: $rawfile("index.html"), controller: this.controller })
......@@ -191,7 +180,7 @@ javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Arr
| object | object | 是 | - | 参与注册的对象。只能声明方法,不能声明属性。 |
| name | string | 是 | - | 注册对象的名称,与window中调用的对象名一致。 |
| methodList | Array\<string\> | 是 | - | 参与注册的应用侧JavaScript对象的方法。 |
| controller | [WebController](#webcontroller) [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | 是 | - | 控制器。 |
| controller | [WebController](#webcontroller) \| [WebviewController](../apis/js-apis-webview.md#webviewcontroller) | 是 | - | 控制器。 |
**示例:**
......@@ -468,7 +457,7 @@ geolocationAccess(geolocationAccess: boolean)
mediaPlayGestureAccess(access: boolean)
设置有声视频播放是否需要用户手动点击,静音视频播放不受该接口管控。
设置有声视频播放是否需要用户手动点击,静音视频播放不受该接口管控,默认需要
**参数:**
......@@ -1155,7 +1144,7 @@ forceDarkAccess(access: boolean)
pinchSmooth(isEnabled: boolean)
设置网页是否开启捏合流畅模式。
设置网页是否开启捏合流畅模式,默认不开启
**参数:**
......@@ -4324,7 +4313,7 @@ setCookie(url: string, value: string): boolean
Column() {
Button('setCookie')
.onClick(() => {
let result = this.controller.getCookieManager().setCookie("www.example.com", "a=b")
let result = this.controller.getCookieManager().setCookie("https://www.example.com", "a=b")
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.
先完成此消息的编辑!
想要评论请 注册