Search code examples
xulthunderbird

How to open a dialog in modal-mode


What's the correct method, to open up a new dialog so that the user cannot return to the main window until the modal dialog is closed.

A typical modal window is created by the alert() function.

I've tried it like this without success:

.openWindow(null, "chrome://myapp/content/mywindow.xul","mywindow", 
"chrome,centerscreen,all,modal",null);

Solution

  • You forgot to mention that you are using nsIWindowWatcher.

    For the window to be modal you need to specify which window it needs to be modal to. If the first parameter to your openWindow() call is null then the window watcher won't know which window opened the dialog (which window needs to be suspended until the dialog is closed). In other words:

    watcher.openWindow(mainWin, "chrome://myapp/content/mywindow.xul", "mywindow",
                       "chrome,centerscreen,all,modal", null);
    

    Or simpler:

    mainWin.openWindow("chrome://myapp/content/mywindow.xul", "mywindow",
                       "chrome,centerscreen,all,modal");
    

    See window.openDialog().