I tried this but failed:
var win = showModalDialog('http://localhost/index.php');
win.close();
I tried this but failed:
var win = showModalDialog('http://localhost/index.php');
win.close();
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
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.
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.