# API

**Kind**: interface | **Module**: [IFrames](https://docs.interop.io/browser/reference/javascript/iframes/index.md) | **Access**: `io.iframes`

**Source**: https://docs.interop.io/browser/reference/javascript/iframes/api/index.html

IFrames API.

## Properties

- **`version`** (`string`, required)
  Version of the IFrames API.

## Methods

### onCloseRequested

Notifies when an app that has been opened in an `<iframe>` element is about to be closed.
This method notifies about close requests only for `<iframe>` elements that have been created inside the current app instance.

```ts
(callback: (instance: Instance, confirmClose: () => Promise<void>) => Promise<void>) => Unsubscribe
```

**Parameters**

- **`callback`** (`(instance: Instance, confirmClose: () => Promise<void>) => Promise<void>`, required)
  Callback function for handling the event. Receives as a first argument an object describing the app instance that is about to be closed.
  Receives as a second argument a function that can be invoked to confirm to the io.Connect framework that the `<iframe>` element can be removed from the DOM.

**Returns**: `Unsubscribe`

### openApp

Opens an app instance in a newly created `<iframe>` element within the current app instance.
The app to open must be defined as an io.Connect app within the io.Connect framework.
It's also required to provide a container HTML element to which the newly created `<iframe>` will be appended as a child.
When the app is closed, you are responsible for removing the parent container element from the DOM if it's no longer needed.
You must not alter the `id` and `name` attributes of the created `<iframe>` element, as they are used by the IFrames API to identify the app instance.

```ts
(config: OpenAppConfig) => Promise<Instance>
```

**Parameters**

- **`config`** (`OpenAppConfig`, required)
  Settings for opening the app in an `<iframe>` element.

**Returns**: `Promise<Instance>`

## Related types

- [Instance](https://docs.interop.io/browser/reference/javascript/iframes/instance/index.md)
- [OpenAppConfig](https://docs.interop.io/browser/reference/javascript/iframes/openappconfig/index.md)
- [Unsubscribe](https://docs.interop.io/browser/reference/javascript/workspaces/unsubscribe/index.md)
