How to close dialog opened by showModalDialog?
I tried this but fai开发者_开发知识库led:
var win = showModalDialog('http://localhost/index.php');
win.close();
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.
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
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.
If you want to close it from inside the modal dialog you can use:
$(".ui-dialog-titlebar-close", parent.document).trigger("click");
精彩评论