tags:

views:

20

answers:

1

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)?

A: 

As you can read in a comment on the MSDN page about showModalDialog (thanks to 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.

Marcel Korpel
Excellent, thanks
Rubans