Custom HTML Dialog in Electron

隐身守侯 提交于 2020-11-29 08:30:22

问题


How (or is it even possible) to use custom HTML dialogs in Electron? I know that Electron provides certain dialogs (showMessageDialog, showErrorDialog) but these do not seem to allow custom HTML.

I do not wish to use native HTML dialogs (dialog) tag as it does not 'blend in' with the user interface.

Any help would be much appreciated. Thanks!


回答1:


You can create a BrowserWindow that's modal and, if you like, frameless. See http://electron.atom.io/docs/api/browser-window/.




回答2:


Yes. On your parent you should have:

const { remote } = require('electron');
const { BrowserWindow } = require('electron').remote;

and then:

let child = new BrowserWindow({
        parent: remote.getCurrentWindow(), 
        modal: true, 
        width:300, height:300,
        webPreferences: {
            enableRemoteModule: true,
            nodeIntegration: true
        }
    });
child.loadFile('myCustomModal.html');

On myCustomModal.html remeber to include a way to close the modal! like:

<button id="cancel-btn">Cancel</button>
<script>
 const remote = require('electron').remote;

  document.getElementById("cancel-btn").addEventListener("click", function (e) {
       var window = remote.getCurrentWindow();
       window.close();
  });   

</script>   


来源:https://stackoverflow.com/questions/39170104/custom-html-dialog-in-electron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!