• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1538
  • Last Modified:

How to reference window showModalDialog from a window opened from it? Javascript

I have a requirement to submit a hidden form in a showModalDialog Window from a normal window which was opened from the showModalDialog.
With normal window.open method, I was using the following code, which is not working when used with a showModalDialog window.

function update() {
     if (window.opener && !window.opener.closed)  {
     window.opener.document.forms['form_2'].submit();
    }
 }  

The window.opener is not working here. How to reference showModalDialog Window  from a popup opened from it?
0
chasun
Asked:
chasun
  • 3
  • 3
1 Solution
 
numberkruncherCommented:
The popup should be able to access its parent window by:
window.opener.form_2.submit();

Open in new window

0
 
chasunAuthor Commented:
No it is not working with showModalDialog Window.
0
 
numberkruncherCommented:
Is this web page and showModalDialog window available online? If so, would you be able to link me to it so that I can take a closer look?

Cheers,
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
chasunAuthor Commented:
Sorry. It is not available online.
After posting the question I came across this write-up, which I am not able to implement. Can you help me understand this concept?

The window.showModalDialog is simply a dialog.  It does not have any real relationship to the calling window, except that it returns a single value to the calling code. It does not have a window.opener property, and it does not provide a handle to the dialog window through the calling code - it simply provides a single, scalar return value once the window is closed.
A way to overcome this is by using an iframe in the window like ..

  <iframe name="receivedDlg" width="100%" height="100%" src="/<computed text>/your_dlg?OpenForm&<computed text>" frameborder="0"></iframe>

The first computed text computes the relative path to the db, and the second computed text pulls the query string values off of the URL and passes them on to the "real" dialog form. By loading the "real" dialog form into the iframe, you get all the from the modal dialog bowindow. One of the parameters of the showModalDialog method is the dialogArguments parameter . This allows you to pass an entity - a value, an object, etc. - to the modal dialog for processing. Well, you can pass the calling window to the modal dialog by using the self object, like this:

window.showModalDialog(your_url, self, your_args)

And then in the JSHeader of your dialog form you can retrieve the window.opener like this:

        if (window.opener) {
                parentdoc = window.opener.document
        } else {
                var dargs = window.dialogArguments;
                parentdoc = dargs.document
        };

This code checks for an opener object, and if one isn't found the object is retrieved from the dialogArguments property, which contains the self object passed in the showModalDialog method.
0
 
numberkruncherCommented:
In that case, can you not just submit your form directly after receiving the returned result from the modal dialog?

You should also be able to pass a function in as an argument, and then call that from within the modal dialog. That function could be a method which submits your form.
var result = window.showModalDialog(your_url, self, your_args);
if (result) {
   form_2.submit();
}

Open in new window

0
 
chasunAuthor Commented:
In my case the query and result is not in the modal dialog, It is happening in a child window (target =_ blank) opened from it.  Here the modal dialog is the parent. How to communicate from the child to  parent window to submit the form in the parent window?
Is there any other method than using an iframe?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now