Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-03-31
6
Medium Priority
?
1,511 Views
Last Modified: 2012-05-06
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
Comment
Question by:chasun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24034928
The popup should be able to access its parent window by:
window.opener.form_2.submit();

Open in new window

0
 

Author Comment

by:chasun
ID: 24041227
No it is not working with showModalDialog Window.
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24041630
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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:chasun
ID: 24043029
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
 
LVL 13

Accepted Solution

by:
numberkruncher earned 375 total points
ID: 24044375
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
 

Author Comment

by:chasun
ID: 24044889
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question