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

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

[Webinar] Streamline your web hosting managementRegister Today

x
 
AerosSagaConnect With a Mentor Commented:
<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
 
JAMESAuthor Commented:
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
 
AerosSagaCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AerosSagaCommented:
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
 
JAMESAuthor Commented:
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
 
AerosSagaCommented:
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
 
praneethaCommented:
0
 
AerosSagaCommented:
You should really use regular javascript though, developing with IE exclusive methods is not wise.
0
All Courses

From novice to tech pro — start learning today.