Home > SYS_IFrame > closeIFrame
SYS_IFrame.closeIFrame() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Close iframe window
Signature
typescript
function closeIFrame(id?: string): Promise<boolean>;1
Parameters
Parameter | Type | Description |
|---|---|---|
id | string | (Optional) Iframe window ID. If not passed in, all iframe windows opened by this extension will be closed |
Returns
Promise<boolean>
Whether the operation is successful
Remarks
Close the iframe window with the specified ID
Note: This API is only valid for extensions. Calling it in a standalone script environment will always throw Error
Example
javascript
// 1. 打开两个内联框架窗口(自建 fixture,演示按 ID 定向关闭)
await eda.sys_IFrame.openIFrame('/extension.json', 300, 200, '嘉立创示例_窗口A', { title: '嘉立创示例 窗口A' });
await eda.sys_IFrame.openIFrame('/extension.json', 300, 200, '嘉立创示例_窗口B', { title: '嘉立创示例 窗口B' });
console.log('已打开两个窗口:嘉立创示例_窗口A / 嘉立创示例_窗口B');
// 2. 按 ID 关闭指定窗口
const closedById = await eda.sys_IFrame.closeIFrame('嘉立创示例_窗口A');
console.log('按 ID 关闭窗口 A 结果:', closedById);
// 3. 不传 id,关闭本扩展打开的全部剩余窗口(清理窗口 B,还原界面)
const closedAll = await eda.sys_IFrame.closeIFrame();
console.log('关闭全部剩余窗口结果:', closedAll);
// 4. 对已不存在的窗口再关闭一次,验证幂等语义(返回 true 而非 false)
const closedAgain = await eda.sys_IFrame.closeIFrame('嘉立创示例_窗口A');
console.log('重复关闭已关窗口结果:', closedAgain);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16