Child window calling function in parent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reply Via Newsgroup

    #1

    Child window calling function in parent


    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.fu nctionName(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
  • Michael Winter

    #2
    Re: Child window calling function in parent

    On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
    <reply-to-newsgroup@pleas e.com> wrote:
    [color=blue]
    > Can I have a script, available in a parent function, called from a child
    > window?[/color]

    Assuming that the script in question has been loaded and parsed, yes.
    [color=blue]
    > If so, how?[/color]

    Use the window.opener property to refer to the parent window. The use of
    self, top, and parent relates to frames, not open windows.
    [color=blue]
    > 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...[/color]

    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]
    [color=blue]
    > 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?[/color]

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

    opener.myFuncti on();
    opener.myVar = 'some value';

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Reply Via Newsgroup

      #3
      Re: Child window calling function in parent

      Michael Winter wrote:[color=blue]
      > On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
      > <reply-to-newsgroup@pleas e.com> wrote:
      >[color=green]
      >> Can I have a script, available in a parent function, called from a
      >> child window?[/color]
      >
      >
      > Assuming that the script in question has been loaded and parsed, yes.
      >[color=green]
      >> If so, how?[/color]
      >
      >
      > Use the window.opener property to refer to the parent window. The use of
      > self, top, and parent relates to frames, not open windows.
      >[color=green]
      >> 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...[/color]
      >
      >
      > 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]
      >[color=green]
      >> 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?[/color]
      >
      >
      > Just as you would with frames, only using the window.opener property:
      >
      > opener.myFuncti on();
      > opener.myVar = 'some value';
      >
      > Mike
      >[/color]


      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.

      Comment

      Working...