C. Reinhold
C. Reinhold

Reputation: 53

Show dialog on top of all other windows

Is there a way to show the dialog from dialog.showMessageBox() on top of everything?

For example, I'm woking on the notepad and given some event in my Electron application it will open a dialog that should now be the main window for the user to see.

Upvotes: 5

Views: 4164

Answers (3)

Thomas Kainrad
Thomas Kainrad

Reputation: 2830

For many use cases, the correct approach will be to pass the existing main window to showMessageBox:

dialog.showMessageBox(mainWindow, dialogOpts)

This will make the message box a modal of the main window. The user will need to close the modal before being able to continue using the main window.

Upvotes: 0

Pipe
Pipe

Reputation: 21

const { remote } = require("electron")
dialog.showMessageBox(**remote.getCurrentWindow()**, [options])

Set the first parameter

Upvotes: 2

pergy
pergy

Reputation: 5531

It's kinda ugly but you can pass a dummy holder browserwindow which is always on top.

dialog.showMessageBox(
  new BrowserWindow({
    show: false,
    alwaysOnTop: true
  }),
  {
    type: 'question',
    message: 'is on top'
  }
)

Upvotes: 6

Related Questions