Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom HTML Dialog in Electron

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!

like image 687
Theo Avatar asked Aug 26 '16 15:08

Theo


2 Answers

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

like image 166
Marc Rochkind Avatar answered Nov 07 '22 02:11

Marc Rochkind


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>   
like image 3
Marco Chacon Avatar answered Nov 07 '22 02:11

Marco Chacon