Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Child window calling function in parent

Reply
Thread Tools

Child window calling function in parent

 
 
Reply Via Newsgroup
Guest
Posts: n/a
 
      04-03-2004

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 With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      04-03-2004
On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
<(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)d (replace ".invalid" with ".uk" to reply)
 
Reply With Quote
 
 
 
 
Reply Via Newsgroup
Guest
Posts: n/a
 
      04-03-2004
Michael Winter wrote:
> On Sat, 03 Apr 2004 01:38:48 GMT, Reply Via Newsgroup
> <(E-Mail Removed)> 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 With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Calling function in a child window from main parent window Bhishm Javascript 2 09-03-2007 11:08 PM
Calling function in a child window from main parent window Bhishm ASP .Net 2 09-03-2007 07:22 PM
Results from child window submit into parent window, then child closes -- How To? Spammay Blockay Javascript 1 02-04-2005 12:47 PM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM



Advertisments