Child window calling function in parent

Discussion in 'Javascript' started by Reply Via Newsgroup, Apr 3, 2004.

  1. Folks,

    I was sure this could be done - or at least sure I had seen reference to
    it at some point or other - but now, after having gone for a cup of tea,
    am begining to doubt my original belief.

    Can I have a script, available in a parent function, called from a child
    window? If so, how?

    And... if so, why? I mean, while sipping my tea, I realised that if the
    child window had a <script src> tag calling a javascript file that was
    already cached, then it would (in theory) be instantly available...

    My attempts so far have revolved around trying object 'calls' like
    top.document.functionName(arg1, arg2) but this has failed.

    and... if I have a variable defined in a script file, loaded in the
    parent window, how can I refer to it from the child window?

    All help, via the newsgroup please, is much apprecaited, thanks
    randelld
     
    Reply Via Newsgroup, Apr 3, 2004
    #1
    1. Advertising

  2. On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
    <> wrote:

    > Can I have a script, available in a parent function, called from a child
    > window?


    Assuming that the script in question has been loaded and parsed, yes.

    > If so, how?


    Use the window.opener property to refer to the parent window. The use of
    self, top, and parent relates to frames, not open windows.

    > And... if so, why? I mean, while sipping my tea, I realised that if the
    > child window had a <script src> tag calling a javascript file that was
    > already cached, then it would (in theory) be instantly available...


    If cached, the file will be available. However, that doesn't mean that
    it's been parsed, and it's functions and variables ready.

    [snipped call with top]

    > and... if I have a variable defined in a script file, loaded in the
    > parent window, how can I refer to it from the child window?


    Just as you would with frames, only using the window.opener property:

    opener.myFunction();
    opener.myVar = 'some value';

    Mike

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
     
    Michael Winter, Apr 3, 2004
    #2
    1. Advertising

  3. Michael Winter wrote:
    > On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
    > <> wrote:
    >
    >> Can I have a script, available in a parent function, called from a
    >> child window?

    >
    >
    > Assuming that the script in question has been loaded and parsed, yes.
    >
    >> If so, how?

    >
    >
    > Use the window.opener property to refer to the parent window. The use of
    > self, top, and parent relates to frames, not open windows.
    >
    >> And... if so, why? I mean, while sipping my tea, I realised that if
    >> the child window had a <script src> tag calling a javascript file that
    >> was already cached, then it would (in theory) be instantly available...

    >
    >
    > If cached, the file will be available. However, that doesn't mean that
    > it's been parsed, and it's functions and variables ready.
    >
    > [snipped call with top]
    >
    >> and... if I have a variable defined in a script file, loaded in the
    >> parent window, how can I refer to it from the child window?

    >
    >
    > Just as you would with frames, only using the window.opener property:
    >
    > opener.myFunction();
    > opener.myVar = 'some value';
    >
    > Mike
    >



    Thanks - My javascript skills are getting better and better - clear
    answers like what you've offered above that I've got from this newsgroup
    over the past months deserve alot of credit.

    Cheers,
    Randell D.
     
    Reply Via Newsgroup, Apr 4, 2004
    #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. Bhishm
    Replies:
    2
    Views:
    799
    bruce barker
    Sep 3, 2007
  2. Noel Dolan
    Replies:
    0
    Views:
    242
    Noel Dolan
    Jul 18, 2004
  3. Spammay Blockay
    Replies:
    1
    Views:
    500
    Dietmar Meier
    Feb 4, 2005
  4. Bhishm
    Replies:
    2
    Views:
    218
    Thomas 'PointedEars' Lahn
    Sep 4, 2007
  5. Bitswapper
    Replies:
    5
    Views:
    153
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page