---
name: "createWebviewContext"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "ty.createWebviewContext - 创建 web-view 上下文 WebviewContext 对象"
---

## createWebviewContext

> [VERSION] Base Library >= 2.21.8

> 💡 The returned WebviewContext is bound to a web-view component via the ID and can send messages to it or reload it.

### Description

Create a web-view context (WebviewContext) object

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | ID of the web-view component |

### Return Value

Type: `WebviewContext`

WebviewContext instance

### Examples

#### Create web-view context

```ts
Page({
  onReady() {
    const webviewCtx = ty.createWebviewContext('myWebview');
    webviewCtx.postMessage({ data: { action: 'init' } });
  },
});
```
