468,720 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

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.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
Jul 23 '05 #1
2 7713
On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
<re****************@please.com> 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
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
Michael Winter wrote:
On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
<re****************@please.com> 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.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bill Borg | last post: by
1 post views Thread by jd | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.