电子:带有表单的对话框消息框

时间:2019-03-15 10:46:15

标签: javascript html electron

是否可能获得带有表单或输入的信息对话框?
这个想法是,如果我们单击btnDialog,它将打开对话框,我们可以在其中定义value1的值或不定义value1的值。

html:

<button id="btnDialog">Define value1</button>

渲染器:

var value1 = 0;
document.getElementById("btnDialog").onclick = function(){
   ipcRenderer.send('opend');
}
ipcRenderer.on('returnd',(event,index)=>{
   if(index==0){
       //value1 = value of input
   }
});

主要:

ipcMain.on('opend',(event)=>{
    const options = {
        type:'info',
        title: 'Title',
        buttons:['OK','Cancel'],
        message: 'Define value1 <form><input></input></form>'
    };
    dialog.showMessageBox(options,(index)=>{
      event.sender.send('returnd',index);
    });
});

如果有必要,我看不到如何从表单中获取价值。
预先感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

简答是“否”,您不能从 idValue=[] for element in links: idValue.append(element.get_attribute("id")) 中提取表格值。

MessageBox API非常清楚,即使像上面一样使用异步回调时,它也只返回按下按钮的索引。

完成目标的正确方法是构建一个新的Browser Window,其中应包含正确的格式并且可以正确地进行交互。

此外,如果要从窗口中删除Chrome,则可以添加Frameless Window Settings

无论哪种情况,您都将使用普通的消息传递API在主进程和浏览器窗口之间进行通信。