2nd call from child window to parent fails

Discussion in 'ASP .Net' started by =?Utf-8?B?QmlsbCBCb3Jn?=, Jun 6, 2005.

  1. Hello all,

    Simple chat app, where the site owner has a master window with all requests
    for chat, status of each room, etc., and child windows for each separate chat
    in which the owner is engaged. When the owner closes one of his child
    windows, I want to update the master window.

    I understand "reasonably" well how to go about this. The master window
    launches the children, and maintains an associative array to keep track of
    each one. When a child closes, I want it to tell the master to remove it from
    its list (this will happen on periodic polling from the master as well). So,
    child.unload calls window.opener.removeMe.

    The problem is that the first time a child calls removeMe on the parent, it
    seems to work, but on the second I get "object doesn't support this
    property...". I've stripped everything down to the barest html as follows,
    where as you'll see the parentPage fires up a childPage, and the childPage
    has a button to run a function in the parent. First time I click the button I
    get expected behavior, but the second time I get the same "object doesn't
    support..." error, even though window.opener still appears valid.

    *testParent.html*
    <html>
    <head>
    <script>
    function startRequest() {
    w = window.open('testChild.html', 'myChild');
    }
    function childCall() {
    document.write('Child did this...');
    }
    </script>
    </head>
    <body onload="startRequest();">
    </body>
    </html>

    * testChild.html *
    <html>
    <head>
    <script>
    function updateParent() {
    window.opener.childCall();
    }
    </script>
    </head>
    <body>
    <form>
    <input type=button value="Update Parent" onclick="updateParent();">
    </form>
    </body>
    </html>

    I think I'm missing something fundamental re scope and/or lifetime, but
    don't see it. Any tips are greatly appreciated.

    Thanks,

    Bill
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Jun 6, 2005
    #1
    1. Advertising

  2. P.S. I now see the problem, but still don't understand what's happening. When
    I call the parent function 'childCall()', the document.write in there is
    overwriting the parent window with the child window, including location, etc.
    If instead of doing document.write I do, say, divMyParentLabel='..whatever'
    I'm good to go. Might be implicit open/close on the document object, or maybe
    I'm not understanding the scope of the parent/child function calls and which
    'document' is in play. Any additional thoughts are appreciated.

    "Bill Borg" wrote:

    > Hello all,
    >
    > Simple chat app, where the site owner has a master window with all requests
    > for chat, status of each room, etc., and child windows for each separate chat
    > in which the owner is engaged. When the owner closes one of his child
    > windows, I want to update the master window.
    >
    > I understand "reasonably" well how to go about this. The master window
    > launches the children, and maintains an associative array to keep track of
    > each one. When a child closes, I want it to tell the master to remove it from
    > its list (this will happen on periodic polling from the master as well). So,
    > child.unload calls window.opener.removeMe.
    >
    > The problem is that the first time a child calls removeMe on the parent, it
    > seems to work, but on the second I get "object doesn't support this
    > property...". I've stripped everything down to the barest html as follows,
    > where as you'll see the parentPage fires up a childPage, and the childPage
    > has a button to run a function in the parent. First time I click the button I
    > get expected behavior, but the second time I get the same "object doesn't
    > support..." error, even though window.opener still appears valid.
    >
    > *testParent.html*
    > <html>
    > <head>
    > <script>
    > function startRequest() {
    > w = window.open('testChild.html', 'myChild');
    > }
    > function childCall() {
    > document.write('Child did this...');
    > }
    > </script>
    > </head>
    > <body onload="startRequest();">
    > </body>
    > </html>
    >
    > * testChild.html *
    > <html>
    > <head>
    > <script>
    > function updateParent() {
    > window.opener.childCall();
    > }
    > </script>
    > </head>
    > <body>
    > <form>
    > <input type=button value="Update Parent" onclick="updateParent();">
    > </form>
    > </body>
    > </html>
    >
    > I think I'm missing something fundamental re scope and/or lifetime, but
    > don't see it. Any tips are greatly appreciated.
    >
    > Thanks,
    >
    > Bill
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Jun 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Filiz Duman
    Replies:
    1
    Views:
    232
    Filiz Duman
    Jan 21, 2004
  2. Noel Dolan
    Replies:
    0
    Views:
    261
    Noel Dolan
    Jul 18, 2004
  3. Spammay Blockay
    Replies:
    1
    Views:
    516
    Dietmar Meier
    Feb 4, 2005
  4. ace danger
    Replies:
    1
    Views:
    127
  5. Bitswapper
    Replies:
    5
    Views:
    174
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page