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