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, and this page is available as Markdown at /apps-plugin/docs/js-api/ui/interaction/enableAlertBeforeUnload.md.

enableAlertBeforeUnload

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

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

扫码预览

扫码预览 enableAlertBeforeUnload

支持版本

前端库版本不低于 0.2.0。

支持平台

平台支持情况
Android支持
iOS支持
PC不支持
HarmonyOS不支持

接入准备

前置条件

  • 必须在页面容器内调用

使用说明

配合 disableAlertBeforeUnload 使用。

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

调用方式

异步 API

enableAlertBeforeUnload(params: EnableAlertBeforeUnloadParams): Promise<object>

入参

名称类型必填默认值约束说明
messagestring是--返回前确认弹窗的文案。

调用示例

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

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

成功返回

无返回字段。

错误处理

错误对象和通用错误码见 通用错误处理。

失败示例

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

错误码

errNoerrMsg平台触发条件处理建议
103feature not supportAndroid、iOS当前调用不来自页面容器请在页面生命周期内调用。
104invalid parameterAndroid、iOSmessage 缺失或类型不是字符串传入字符串类型的 message。

通用错误码

errNoerrMsg说明平台
102internal error内部错误Android、iOS