未验证 提交 810e8d2a 编写于 作者: O openharmony_ci 提交者: Gitee

!13424 webview 新增页面状态保存恢复等接口文档

Merge pull request !13424 from 李想/master
......@@ -2750,6 +2750,104 @@ struct WebComponent {
}
```
### pageUp
pageUp(top:boolean): void
将Webview的内容向上滚动半个视框大小或者跳转到页面最顶部,通过top入参控制。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| top | boolean | 是 | 是否跳转到页面最顶部,设置为false时将页面内容向上滚动半个视框大小,设置为true时跳转到页面最顶部。 |
**错误码:**
以下错误码的详细介绍请参见 [webview错误码](../errorcodes/errorcode-webview.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('pageUp')
.onClick(() => {
try {
this.controller.pageUp(false);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### pageDown
pageDown(bottom:boolean): void
将Webview的内容向下滚动半个视框大小或者跳转到页面最底部,通过bottom入参控制。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------- | ---- | ------------------------------------------------------------ |
| bottom | boolean | 是 | 是否跳转到页面最底部,设置为false时将页面内容向下滚动半个视框大小,设置为true时跳转到页面最底部。 |
**错误码:**
以下错误码的详细介绍请参见 [webview错误码](../errorcodes/errorcode-webview.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('pageDown')
.onClick(() => {
try {
this.controller.pageDown(false);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### getBackForwardEntries
getBackForwardEntries(): BackForwardList
......@@ -2799,6 +2897,122 @@ struct WebComponent {
}
```
### serializeWebState
serializeWebState(): Uint8Array
将当前Webview的页面状态历史记录信息序列化。
**系统能力:** SystemCapability.Web.Webview.Core
**返回值:**
| 类型 | 说明 |
| ---------- | --------------------------------------------- |
| Uint8Array | 当前Webview的页面状态历史记录序列化后的数据。 |
**错误码:**
以下错误码的详细介绍请参见 [webview错误码](../errorcodes/errorcode-webview.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('serializeWebState')
.onClick(() => {
try {
let state = this.controller.serializeWebState();
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o2 | 0o100, 0o666);
fileio.writeSync(fd, state.buffer);
fileio.closeSync(fd);
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### restoreWebState
restoreWebState(state: Uint8Array): void
当前Webview从序列化数据中恢复页面状态历史记录。
**系统能力:** SystemCapability.Web.Webview.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------- | ---- | ---------------------------- |
| state | Uint8Array | 是 | 页面状态历史记录序列化数据。 |
**错误码:**
以下错误码的详细介绍请参见 [webview错误码](../errorcodes/errorcode-webview.md)
| 错误码ID | 错误信息 |
| -------- | ------------------------------------------------------------ |
| 17100001 | Init error. The WebviewController must be associated with a Web component. |
**示例:**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio';
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController();
build() {
Column() {
Button('RestoreWebState')
.onClick(() => {
try {
let path = globalThis.AbilityContext.cacheDir;
path += '/WebState';
let fd = fileio.openSync(path, 0o002, 0o666);
let stat = fileio.fstatSync(fd);
let size = stat.size;
let buf = new ArrayBuffer(size);
fileio.read(fd, buf, (err, data) => {
if (data) {
this.controller.restoreWebState(new Uint8Array(data.buffer));
}
fileio.closeSync(fd);
});
} catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
}
})
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
```
### customizeSchemes
static customizeSchemes(schemes: Array\<WebCustomScheme\>): void
......@@ -4469,6 +4683,8 @@ Web组件返回的请求/响应头对象。
用于描述[WebMessagePort](#webmessageport)所支持的数据类型。
**系统能力:** SystemCapability.Web.Webview.Core
| 类型 | 说明 |
| -------- | -------------------------------------- |
| string | 字符串类型数据。 |
......@@ -4492,10 +4708,10 @@ Web组件返回的请求/响应头对象。
**系统能力:** SystemCapability.Web.Webview.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------ | ------ | ---- | ---- | ---------------------------- |
| currentIndex | number | 是 | 否 | 当前页面在页面历史列表中的索引。 |
| size | number | 是 | 否 | 历史列表中索引的数量 |
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| currentIndex | number | 是 | 否 | 当前在页面历史列表中的索引。 |
| size | number | 是 | 否 | 历史列表中索引的数量,最多保存50条,超过时起始记录会被覆盖。 |
### getItemAtIndex
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册