Passing values between parent and child windows - Beginner question

Discussion in 'Javascript' started by evrimagha@hotmail.com, Aug 27, 2007.

  1. Guest

    Hello JS newsgroup


    The main window of my Website opens a child window as you can see
    below:

    <script language="JavaScript">

    window.name='Iamparentwindow'

    function openwindow()
    {
    var
    child2=window.open("Test.htm","childwin","height=350,width=280");
    child2.focus();
    child2.document.childform.text1.value =
    document.parentform.testtext2.value;

    }
    </script>


    I have some questions

    1. the 3rd line of function openwindow is generating errors- Could you
    please help me fix that ?

    2. In the child window, I have used
    opener.document.parentform.testtext1.value =
    document.childform.text2.value;

    which is working fine. But I would like to use the name of opener
    window, "Iamparentwindow" instead.
    Could you please help me?

    Thank you in advance
    Evrim
    , Aug 27, 2007
    #1
    1. Advertising

  2. Stevo Guest

    wrote:
    > var child2=window.open("Test.htm","childwin","height=350,width=280");
    > child2.focus();
    > child2.document.childform.text1.value = document.parentform.testtext2.value;
    > I have some questions
    >
    > 1. the 3rd line of function openwindow is generating errors- Could you
    > please help me fix that ?


    You're trying to immediately access the document of the child window
    before the browser has probably even got around to opening it. It
    certainly won't have loaded Test.htm into it and rendered the page
    completely. window.open is NOT a blocking call (i.e. your javascript
    doesn't wait for it to have loaded Test.htm into it before it comes back
    and executes line 3 of your code.

    I think you're going to have to split your function into two parts and
    have the second part wait for the page to have loaded. You could poll it
    (check every so often to see if that childform exists yet) or the child
    could make a call into the parent indicating it's ready and waiting.

    > 2. In the child window, I have used
    > opener.document.parentform.testtext1.value =
    > document.childform.text2.value;
    >
    > which is working fine. But I would like to use the name of opener
    > window, "Iamparentwindow" instead.
    > Could you please help me?


    How about this?

    var Iamparentwindow = opener.document;
    Iamparentwindow.parentform.~~~~
    Stevo, Aug 27, 2007
    #2
    1. Advertising

  3. wrote:
    <snip>
    > The main window of my Website opens a child window as
    > you can see below:


    No. It is a beginner's mistake to assume that attempting to open a new
    browser window will result in a new browser window being opened. Your
    action only MAY open a new browser window, and you will not achieve a
    reliable outcome until you design out any supposed need to open new
    browser windows.

    > <script language="JavaScript">
    >
    > window.name='Iamparentwindow'
    >
    > function openwindow()
    > {
    > var
    > child2=window.open("Test.htm","childwin","height=350,width=280");
    > child2.focus();
    > child2.document.childform.text1.value =
    > document.parentform.testtext2.value;
    >
    > }
    > </script>
    >
    >
    > I have some questions
    >
    > 1. the 3rd line of function


    The way you have wrapped the code in your posting (and it was you not
    your newsreader as the ultimate control is yours) has made it unclear as
    to which line is (or was) the third.

    > openwindow is generating errors-
    > Could you please help me fix that ?


    Yes, the newly opened window (if it opens at all) will request a web
    page from the server, but receiving and processing whatever the server
    sends back in response to that request will take an unpredictable (but
    non-zero) amount of time. Do not attempt to interact with any document
    supposed to be contained within that window until you have positive
    verification that the document has arrived from the server and been
    processed by the browser.

    > 2. In the child window, I have used
    > opener.document.parentform.testtext1.value =
    > document.childform.text2.value;
    >
    > which is working fine. But I would like to use the
    > name of opener window, "Iamparentwindow" instead.
    > Could you please help me?


    Yes, stop wanting that. Then you will no longer care that it isn't going
    to be possible.

    Richard.
    Richard Cornford, Aug 27, 2007
    #3
    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. Noel Dolan
    Replies:
    0
    Views:
    217
    Noel Dolan
    Jul 18, 2004
  2. orion30
    Replies:
    2
    Views:
    95
  3. Patient Guy
    Replies:
    1
    Views:
    147
    lallous
    Sep 16, 2005
  4. Replies:
    0
    Views:
    313
  5. Bitswapper
    Replies:
    5
    Views:
    119
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page