electron 显示对话框 showMessageBoxSync showMessageBox
7.3.2的文档:https://github.com/electron/electron/blob/v7.3.2/docs/api/dialog.md 不同版本可以切换
一个是同步对话框,另外一个是异步。
同步:
//will-prevent-unload这个事件只会在弹出框关闭时触发,比如alert,confirm
win.webContents.on('will-prevent-unload', (event) => {
console.log(" ==cust_event_notify_dialog_confirm=="); const options = { type: 'question', buttons: ['Cancel', 'Yes, please', 'No, thanks'], defaultId: 2, cancelId: 0, title: 'Question', message: 'my window?', detail: 'It does not really matter', checkboxLabel: 'remember', checkboxChecked: true, }; const choice= dialog.showMessageBoxSync(win, options); const isCancel = (choice === 0) if (!isCancel) { event.preventDefault()//确认 } })
异步:
// 窗口关闭 win.on('close', (e) => { e.preventDefault(); dialog.showMessageBox(win, { type: 'warning', title: '关闭', message: '是否退出?', buttons: ['取消', '确定'] }).then((index) => { if (index.response === 1) { win = null; app.exit(); } }); });
标签:
electron
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2018-08-06 为什么每次app访问服务器都建立新连接 导致服务器大量连接疯涨
2015-08-06 udp内网穿透 两个内网互联
2015-08-06 UDP 内网穿透 心跳
2013-08-06 Ubuntu 13.04下构建Qt5开发环境