0

I tried this but failed:

var win = showModalDialog('http://localhost/index.php');
win.close();
Mask
  • 33,129
  • 48
  • 101
  • 125

4 Answers4

5

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.

lc.
  • 113,939
  • 20
  • 158
  • 187
  • Then is there any way to close the modal dialog with script? – Mask Nov 25 '09 at 09:42
  • Well, the dialog could *close itself* with `window.close()`, but just as @sdwilsh says, you can't do anything from outside of it. – lc. Nov 25 '09 at 18:23
1

When you execute showModalDialog, the entire code sequence is blocked. You need to close the modal window to proceed, however win will be null by then :P

o.k.w
  • 25,490
  • 6
  • 66
  • 63
0

Modal dialog means that next operator is not executed UNTIL the dialog is closed. This is why nothing you place in the next line will ever work.

That's the purpose of modal dialogs - to freeze current window and get some mandatory input from the user. If you want to close it immediately, I suspect that you don't really need a modal dialog.

By the way, return value of showModalDialog is dialog return code, and not a window variable!

Normally, modal dialogs are closed from within. If you don't want to wait for user's input, there must be something in index.php code that closes it.

yu_sha
  • 4,290
  • 22
  • 19
  • How to close it from within,can you be more specific? – Mask Nov 25 '09 at 09:43
  • 1
    You could have onLoad event in the index.php that would set up a timer and call window.close after a while. What are you trying to achieve? Window that blinks and closes? Why? – yu_sha Nov 25 '09 at 12:02
0

If you want to close it from inside the modal dialog you can use:

$(".ui-dialog-titlebar-close", parent.document).trigger("click");