通常当使用 window.open 打开窗口时,我可以使用 window.opener() 访问调用者窗口,是否可以在模态对话框 (window.showModalDialog) 中执行类似操作?
最佳答案
正如您在 comment 中所读到的那样在关于 showModalDialog
的 MSDN 页面上(感谢 Pekka),
[t]he
window.opener
method returnsnull
, rather than a reference to the opening window. So you cannot refresh the opening window withwindow.opener.location.refresh()
(if, for instance, you useshowModalDialog
to open an editing dialog). If all you want to do is refresh the opening window every time theModalDialog
closes, that is easy (includewindow.location.refresh()
right after the call toshowModalDialog
). But if you only want to refresh the opening window in certain cases (e.g., the opening window takes a while to refresh), you can do that by passing adialogArgument
.A more clever (I think) way is to pass the window reference itself as the
dialogArgument
. In the calling window, usewindow.showModalDialog('newurl.asp', window)
. In the called dialog retrieve the reference withvar window_opener = window.dialogArguments
. You can use the window reference stored in variablewindow_opener
in place ofwindow.opener
, to refresh the calling window from the called dialog.Do note that Firefox and Chrome (for instance) do not appear to have these limitations, and appear to treat
ModalDialogs
more like regular windows. Keep that in mind if you do testing using one of these browsers, but intend your application to work in all browsers.
关于javascript - 我可以从 ModalDialog 窗口获取开启器窗口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3109532/