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

标签 javascript

通常当使用 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/

相关文章:

Javascript:用所需的类剥离标签

javascript - 如何从 indexeddb 中获取所有值

javascript - Nightwatch.js 不执行选项卡上的单击操作

javascript - html2canvas打印截图

javascript - 如果第一列显示相等的值,如何使用第二列进行排序

javascript - 如何在不跳到顶部的情况下替换可滚动 div 的内容?

javascript - 当用户使用 javascript 单击查看源时如何保护 img src 路径?

javascript - JS/jQuery : How can I select the first LI item of an UL navigation when hovering over another (lower) LI element?

javascript - Handlebars.js 中的多个循环失败

javascript - 允许并配置访问控制允许来源