如何关闭由showModalDialog打开的对话框?

发布于 2024-08-12 07:59:37 字数 114 浏览 3 评论 0原文

我尝试过这个但失败了:

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

I tried this but failed:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苦妄 2024-08-19 07:59:37

模态窗口的定义是当前函数的执行停止,直到模态窗口关闭。也就是说,对 showModalDialog() 的调用将阻塞,直到显示的对话框关闭。因此,您的 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.

素罗衫 2024-08-19 07:59:37

当您执行 showModalDialog 时,整个代码序列都会被阻塞。您需要关闭模态窗口才能继续,但是到那时 win 将为 null :P

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

百善笑为先 2024-08-19 07:59:37

模态对话框意味着直到对话框关闭才执行下一个运算符。这就是为什么你在下一行中放置的任何内容都不起作用。

这就是模式对话框的目的 - 冻结当前窗口并从用户那里获取一些强制输入。如果您想立即关闭它,我怀疑您实际上并不需要模式对话框。

顺便说一下,showModalDialog 的返回值是对话框返回码,而不是窗口变量!

通常,模式对话框是从内部关闭的。如果您不想等待用户的输入,index.php 代码中必须有某些内容可以关闭它。

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.

酷炫老祖宗 2024-08-19 07:59:37

如果您想从模式对话框内部关闭它,可以使用:

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文