How to close dialog opened by showModalDialog?

Mask picture Mask · Nov 25, 2009 · Viewed 11.9k times · Source

I tried this but failed:

var win = showModalDialog('http://localhost/index.php');
win.close();

Answer

lc. picture lc. · Nov 25, 2009

The definition of a modal window is that execution of the current function stops until the modal window is closed. That is, the call to showModalDialog() will block until the shown dialog is closed. Therefore, your win.close() will be called after the window is already closed (not what you're intending).

You have a couple options:

  • Show the dialog as non-modal and wait in an events loop until a certain condition is met. Then, close the window from the calling function.

  • The modal dialog closes itself at an appropriate time.