gpt4 book ai didi

javascript - 我可以从 ModalDialog 窗口获取开启器窗口吗?

转载 作者:行者123 更新时间:2023-11-30 10:54:16 24 4
gpt4 key购买 nike

通常当使用 window.open 打开窗口时,我可以使用 window.opener() 访问调用者窗口,是否可以在模态对话框 (window.showModalDialog) 中执行类似操作?

最佳答案

正如您在 comment 中所读到的那样在关于 showModalDialog 的 MSDN 页面上(感谢 Pekka),

[t]he window.opener method returns null, rather than a reference to the opening window. So you cannot refresh the opening window with window.opener.location.refresh() (if, for instance, you use showModalDialog to open an editing dialog). If all you want to do is refresh the opening window every time the ModalDialog closes, that is easy (include window.location.refresh() right after the call to showModalDialog). 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 a dialogArgument.

A more clever (I think) way is to pass the window reference itself as the dialogArgument. In the calling window, use window.showModalDialog('newurl.asp',
window)
. In the called dialog retrieve the reference with var
window_opener =
window.dialogArguments
. You can use the window reference stored in variable window_opener in place of window.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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com