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();
            }
        });
});

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM