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?
chasunAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
numberkruncherConnect With a Mentor Commented:
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
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.