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

x
?
Solved

Does a modeless / modal dialog have an window.opener property

Posted on 2004-10-28
9
Medium Priority
?
969 Views
Last Modified: 2008-01-09
Hi,

We are loading a modeless dialog where the user can enter some information.  We would like to write this back to it's parent before closing the window but if we try and specify window.opener etc we receive the error "Microsoft JScript runtime error: 'window.opener.document' is null or not an object".

Any thoughts on how a modeless dialog can refer back to it's parent to store a string?

Thanks.

James.
0
Comment
Question by:JAMES
[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
  • 6
  • 2
9 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 2000 total points
ID: 12436119
<HTML>
 
<script language=JavaScript>
 
       var winmodal;
     
        function ModalDialogMaintainFocus()
        {
            try
            {
                   if (winmodal.closed) { return; }
                   winmodal.focus();
            }
            catch (Exception) { }
        }
       
       
        function ModalDialogShow(BodyText,Buttons,ReturnValueElementName)
          {
                   var args='toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=450';  

                         winmodal=window.open("","",args);
                         winmodal.document.open();
                         winmodal.document.write('<html>');
                         winmodal.document.write('<head>');
                         winmodal.document.write('<script' + ' language=JavaScript>');
                         winmodal.document.write('function CloseForm(Response) ');
                         winmodal.document.write('{ ');
                         winmodal.document.write('   var ret = window.opener.document.getElementById("' + ReturnValueElementName + '"); ');
                         winmodal.document.write('         ret.value = Response; ');
                         winmodal.document.write('         window.close(); ');
                         winmodal.document.write('} ');
                         winmodal.document.write('</script' + '>');        
                         winmodal.document.write('</head>');  
                         winmodal.document.write('<body onblur="window.focus();">');
                         winmodal.document.write('<table border=0 width="80%" align=center cellspacing=0 cellpadding=2>');
                         winmodal.document.write('<tr><td align=left>' + BodyText + '</td></tr>');
                         winmodal.document.write('<tr><td align=left><br></td></tr>');
                         winmodal.document.write('<tr><td align=center>' + Buttons + '</td></tr>');
                         winmodal.document.write('</body>');
                         winmodal.document.write('</html>');
                         winmodal.document.close();
                         winmodal.focus();
                         window.setInterval("ModalDialogMaintainFocus()",5);
 
          }

</script>

<script language=JavaScript>

          function YesNoCancel(ReturnValueElementName)
          {
                 var BodyText = '';
                 var Buttons='';
                 BodyText = 'Please enter yes, no, or cancel';
                 Buttons = '<a href=javascript:CloseForm("Yes");>Yes</a>  ';
                 Buttons += '<a href=javascript:CloseForm("No");>No</a>  ';
                 Buttons += '<a href=javascript:CloseForm("Cancel");>Cancel</a>  ';
                 ModalDialogShow(BodyText,Buttons,ReturnValueElementName);
          }

          function YesNoMaybe(ReturnValueElementName)
          {
                 var BodyText = '';
                 var Buttons='';
                 BodyText = 'Please enter yes, no, or maybe';
                 Buttons = '<a href=javascript:CloseForm("Yes");>Yes</a>  ';
                 Buttons += '<a href=javascript:CloseForm("No");>No</a>  ';
                 Buttons += '<a href=javascript:CloseForm("Maybe");>Maybe</a>  ';
                 ModalDialogShow(BodyText,Buttons,ReturnValueElementName);
          }

</script>
 
<BODY >

  <table border=1 cellpadding=2 cellspacing=2 align=center width="60%">
    <tr><td align=left></td></tr>
    <tr><td align=left></td></tr>
    <tr><td align=left></td></tr>
    <tr>
    <td align=left><a href="javascript:YesNoCancel('modalreturn1');">Show Modal #1</a>
       1. <input type=text id=modalreturn1 name=modalreturn1 value=''></td>
    </tr>
    <tr>
    <td align=left><a href="javascript:YesNoMaybe('modalreturn2');">Show Modal #2</a>
       2. <input type=text id=modalreturn2 name=modalreturn2 value=''></td>
    </tr>
 
  </table>

</BODY>
</HTML>

Aeros
0
 

Author Comment

by:JAMES
ID: 12436149
Thanks Aeros,

I saw this on my other post but havent had chance to look at it in detail yet.

This does seem rather long-winded considering all im trying to do is pass back a string value! (I appreciate the whole lot may not apply to me but it's a lot to decipher).

Do you know the answer to my title questions ie. "Does a modeless / modal dialog have an window.opener property"

Thanks.

James.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12436201
Window.showModalDialog is great in that it provides a truly modal dialog, but it has some serious limitations when wanting to create interactive dialogs. The best way to think of window.showModalDialog is that it is simply a dialog - it gathers values and can return a value. 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 as stated earlier, when called it does not provide a handle to the dialog window through the calling code - it simply provides a single, scalar return value once the box is closed. This can seriously mess up your code if you have interactive dialogs. Another problem I found with showModalDialog - any and all links in the dialog, including "javascript:function" links, launch into a new window - not in the dialog window. This is also undesired behavior. So, how can you get around this? Well, since we're already writing IE-specific code, let's go ahead and use another IE-specific call - iFrames.

http://www.lotusgeek.com/SapphireOak/LotusGeekBlog.nsf/plinks/ROLR-5QT5TD
0
Industry Leaders: 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!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12436229
A very common misinterpretation is that the window.opener property should always be available as long as the creator window still exists. This is true providing the window.opener URL and the new window URL reside on the same domain, or at least on the same second-level domain. If the users navigate away from the domain with one of these windows, Internet Explorer enforces cross-frame scripting security.
0
 

Author Comment

by:JAMES
ID: 12436246
Both windows in my case are within the same domain - I will reread your example.

A simple solution for me for the problem of ""javascript:function" links, launch into a new window " was to include "<base target="_self">" in the <HEAD> section of the child pop up and it then doesnt open a new window - although we are now going off-topic.

James.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12436253
Dialogs, Modal/Modeless

(note: 'Til Microsoft addresses these bugs, there's a free script include called ssDialogFix which fixes most of them.)
document.title

document.title can be dynamically set after a dialog's page load, but those changes are not reflected in the dialog window's title bar.
window targeting

Default window targeting is broken in dialogs. Instead of targeting the current window (_self) by default, it opens a new window. This problem applies to:

    * Hyperlinks (A tags)
    * Form submission
    * All programmatic interactions:
          o window.location = url
          o window.location.href = url
          o window.location.assign(url)
          o window.location.reload(url)
          o window.location.replace(url)
          o window.navigate(url)

window.opener

This property should point to the window object which opened the dialog.

http://channel9.msdn.com/wiki/default.aspx/Channel9.InternetExplorerProgrammingBugs

0
 
LVL 15

Expert Comment

by:praneetha
ID: 12436381
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12436470
You should really use regular javascript though, developing with IE exclusive methods is not wise.
0

Featured Post

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.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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