Solved

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

Posted on 2009-03-31
6
1,376 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
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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
Comment Utility
No it is not working with showModalDialog Window.
0
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:chasun
Comment Utility
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 125 total points
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now