> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# enableAlertBeforeUnload

开启页面返回前提醒。
当用户在应用插件的非最底层页面点击左上角返回按钮、左上角首页按钮或客户端返回键时,弹起询问弹窗

返回询问对话框只会对调用的当前页面生效，通过手势滑动返回时不会弹起询问对话框

## 扫码预览

![扫码预览 enableAlertBeforeUnload](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fui%252Falert-before-unload%252Findex)

## 支持版本

前端库版本不低于 `0.2.0`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 接入准备

### 前置条件

- 必须在页面容器内调用

## 使用说明

配合 disableAlertBeforeUnload 使用。

- 仅非根页面的显式返回会展示提醒；根页面退出不拦截，iOS 侧滑返回不拦截。

## 调用方式

### 异步 API

```typescript
enableAlertBeforeUnload(params: EnableAlertBeforeUnloadParams): Promise<object>
```

## 入参

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必填</th><th>默认值</th><th>约束</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>message</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>返回前确认弹窗的文案。</td></tr>
</tbody>
</table>

## 调用示例

```typescript
import { enableAlertBeforeUnload } from '@doubao-dev/framework/api';

await enableAlertBeforeUnload({ message: '确定离开当前页面吗？' });
```

## 成功返回

无返回字段。

## 错误处理

错误对象和通用错误码见 [通用错误处理](/apps-plugin/docs/js-api/common-errors.md#错误返回)。

### 失败示例

```json
{
  "errNo": 103,
  "errMsg": "feature not support"
}
```

### 错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>平台</th><th>触发条件</th><th>处理建议</th></tr>
</thead>
<tbody>
<tr><td><code>103</code></td><td><code>feature not support</code></td><td>Android、iOS</td><td>当前调用不来自页面容器</td><td>请在页面生命周期内调用。</td></tr>
<tr><td><code>104</code></td><td><code>invalid parameter</code></td><td>Android、iOS</td><td>message 缺失或类型不是字符串</td><td>传入字符串类型的 message。</td></tr>
</tbody>
</table>

#### 通用错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>说明</th><th>平台</th></tr>
</thead>
<tbody>
<tr><td><code>102</code></td><td><code>internal error</code></td><td>内部错误</td><td>Android、iOS</td></tr>
</tbody>
</table>
