Calling function in a child window from main parent window

Discussion in 'Javascript' started by Bhishm, Sep 3, 2007.

  1. Bhishm

    Bhishm Guest

    Hi,

    I am opening a child window from parent using window.open, but on
    refreshing the parent the reference of the child is lost.

    Is there any way to save the reference of the child in the parent
    after refresh.

    I have searched a lot but not able to find any relevant information

    Thanks & Regards,
    Bhishm
    Bhishm, Sep 3, 2007
    #1
    1. Advertising

  2. Bhishm

    Erwin Moller Guest

    Bhishm wrote:
    > Hi,
    >
    > I am opening a child window from parent using window.open, but on
    > refreshing the parent the reference of the child is lost.
    >
    > Is there any way to save the reference of the child in the parent
    > after refresh.
    >
    > I have searched a lot but not able to find any relevant information
    >
    > Thanks & Regards,
    > Bhishm
    >


    Hi,

    If the parent is refreshed, so are all the javascript references.
    The good news is that the CHILD can find the parent by the using
    parent-keyword.

    If that does not help you, you could try to find the childwindow by
    using its name (assuming you don't change that).

    Regards,
    Erwin Moller
    Erwin Moller, Sep 3, 2007
    #2
    1. Advertising

  3. Bhishm wrote:
    > I am opening a child window from parent using window.open, but on
    > refreshing the parent the reference of the child is lost.


    You should get your terminology right. There is no intrinsic parent-child
    relationship a window and another that was opened this way. To avoid
    confusion with frames, where there is a parent-child relationship, it is
    best to say "the opening window/the opener" and "the opened window", or to
    use identifiers like A and B, such as in "window B is opened from window A".

    > Is there any way to save the reference of the child in the parent
    > after refresh.


    There is no way that the opener (the Window object to retain the global
    execution context from which window.open() was called) can retain a
    reference to the opened Window when the former's document is refreshed.
    When that happens, the execution context where a corresponding property was
    set ceases to exist (at least one should not rely on its fully continued
    existence; there are only browser bugs that allow it to "survive" sometimes).

    However, an (X)HTML document (in a window) can contain frames, and a frame
    also is represented by a Window object in DOM Level 0 compliant DOMs (i.e.
    all of the DOMs I have encountered to date). So you could save the
    reference to the opened Window in a property defined in the execution
    context of another frame -- with all the accessibility issues frames imply.
    Say, a frameset contains two frames on the same level named "frameA" and
    "frameB", and that you want to save a value in frameB from frameA:

    window.parent.frames["frameB"].foo = "bar";

    That is relying on frame support, and that the global execution context of a
    window can be referred to by a reference to the Window object that creates
    that context. (It would then be wise to have `foo' declared globally in
    "frameB", to avoid implications with the host object pecularities allowed by
    ECMA-262.)

    But the opened window has a reference to its opener with window.opener in
    *its* execution contexts; the Same Origin Policy obeyed, the opened window
    can regularly be checked for whether its document was fully loaded (using
    window.setTimeout() or window.setInterval()) and then the reference to the
    opened window can be saved again in the global execution context of the opener:

    function checkOpener(t)
    {
    if (window.opener && !window.opener.closed
    && window.opener.document && window.opener.document.body)
    {
    window.clearTimeout(timeout);
    window.opener.foo = "bar";
    }
    else
    {
    timeout = window.setTimeout("checkOpener(" + t + ")", t);
    }
    }

    var t = 500;
    var timeout = window.setTimeout("checkOpener(" + t + ")", t);

    Another possibility includes accessing the opened window by name repeatedly,
    however that would cause its document to reload:

    window.open("foo.html", "windowB", "...");

    The usual feature tests should be applied in all cases.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Sep 4, 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. Jeff Rodriguez
    Replies:
    23
    Views:
    1,116
    David Schwartz
    Dec 9, 2003
  2. Bhishm
    Replies:
    2
    Views:
    797
    bruce barker
    Sep 3, 2007
  3. Noel Dolan
    Replies:
    0
    Views:
    227
    Noel Dolan
    Jul 18, 2004
  4. Spammay Blockay
    Replies:
    1
    Views:
    423
    Dietmar Meier
    Feb 4, 2005
  5. Bitswapper
    Replies:
    5
    Views:
    132
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page