我可以从ModalDialog窗口获取开启窗口吗? [英] Can I get the opener window from a ModalDialog window?

查看:89
本文介绍了我可以从ModalDialog窗口获取开启窗口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Normally when a window is opened using window.open I can access the caller window by using window.opener(), is it possible do the similar within modal dialogs(window.showModalDialog)?

推荐答案

正如您可以阅读 <的MSDN页面上的rel =nofollow noreferrer>评论 code> showModalDialog (感谢Pekka),

As you can read in a comment on the MSDN page about showModalDialog (thanks to Pekka),


[t]他 window.opener 方法返回
null ,而不是对
开启窗口的引用。所以你不能用
刷新
开启窗口 window.opener.location.refresh()
(例如,如果你使用的话)
showModalDialog 打开编辑
对话框)。如果您想要做的只是
刷新开盘窗口,每次
ModalDialog 关闭,这很容易
(包括 window.location.refresh()
在调用
showModalDialog 之后。但是如果你只想
想要在
某些情况下刷新开盘窗口(例如,开盘
窗口需要一段时间来刷新),你
可以通过传递$来做到这一点b $ b dialogArgument

[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.

更聪明(我认为)的方法是
将窗口引用传递给 dialogArgument 即可。在
调用窗口中,使用
window.showModalDialog('newurl.asp',
window)
。在被调用的对话框中,
使用 var
window_opener =
window.dialogArguments
检索引用。您可以使用
存储在
变量 window_opener 中的窗口引用来代替
window.opener ,从被调用的对话框中刷新
调用窗口。

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.

请注意Firefox和Chrome(对于
实例)不似乎有这些
的限制,并且似乎对待
ModalDialogs 更像是普通的
windows。如果您使用其中一种浏览器进行
测试,请记住这一点,
但是打算让您的应用程序在
所有浏览器中运行。

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.

这篇关于我可以从ModalDialog窗口获取开启窗口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆