Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Passing values between parent and child windows - Beginner question

Reply
Thread Tools

Passing values between parent and child windows - Beginner question

 
 
evrimagha@hotmail.com
Guest
Posts: n/a
 
      08-27-2007
Hello JS newsgroup


The main window of my Website opens a child window as you can see
below:

<script language="JavaScript">

window.name='Iamparentwindow'

function openwindow()
{
var
child2=window.open("Test.htm","childwin","height=3 50,width=280");
child2.focus();
child2.document.childform.text1.value =
document.parentform.testtext2.value;

}
</script>


I have some questions

1. the 3rd line of function openwindow is generating errors- Could you
please help me fix that ?

2. In the child window, I have used
opener.document.parentform.testtext1.value =
document.childform.text2.value;

which is working fine. But I would like to use the name of opener
window, "Iamparentwindow" instead.
Could you please help me?

Thank you in advance
Evrim

 
Reply With Quote
 
 
 
 
Stevo
Guest
Posts: n/a
 
      08-27-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> var child2=window.open("Test.htm","childwin","height=3 50,width=280");
> child2.focus();
> child2.document.childform.text1.value = document.parentform.testtext2.value;
> I have some questions
>
> 1. the 3rd line of function openwindow is generating errors- Could you
> please help me fix that ?


You're trying to immediately access the document of the child window
before the browser has probably even got around to opening it. It
certainly won't have loaded Test.htm into it and rendered the page
completely. window.open is NOT a blocking call (i.e. your javascript
doesn't wait for it to have loaded Test.htm into it before it comes back
and executes line 3 of your code.

I think you're going to have to split your function into two parts and
have the second part wait for the page to have loaded. You could poll it
(check every so often to see if that childform exists yet) or the child
could make a call into the parent indicating it's ready and waiting.

> 2. In the child window, I have used
> opener.document.parentform.testtext1.value =
> document.childform.text2.value;
>
> which is working fine. But I would like to use the name of opener
> window, "Iamparentwindow" instead.
> Could you please help me?


How about this?

var Iamparentwindow = opener.document;
Iamparentwindow.parentform.~~~~
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      08-27-2007
(E-Mail Removed) wrote:
<snip>
> The main window of my Website opens a child window as
> you can see below:


No. It is a beginner's mistake to assume that attempting to open a new
browser window will result in a new browser window being opened. Your
action only MAY open a new browser window, and you will not achieve a
reliable outcome until you design out any supposed need to open new
browser windows.

> <script language="JavaScript">
>
> window.name='Iamparentwindow'
>
> function openwindow()
> {
> var
> child2=window.open("Test.htm","childwin","height=3 50,width=280");
> child2.focus();
> child2.document.childform.text1.value =
> document.parentform.testtext2.value;
>
> }
> </script>
>
>
> I have some questions
>
> 1. the 3rd line of function


The way you have wrapped the code in your posting (and it was you not
your newsreader as the ultimate control is yours) has made it unclear as
to which line is (or was) the third.

> openwindow is generating errors-
> Could you please help me fix that ?


Yes, the newly opened window (if it opens at all) will request a web
page from the server, but receiving and processing whatever the server
sends back in response to that request will take an unpredictable (but
non-zero) amount of time. Do not attempt to interact with any document
supposed to be contained within that window until you have positive
verification that the document has arrived from the server and been
processed by the browser.

> 2. In the child window, I have used
> opener.document.parentform.testtext1.value =
> document.childform.text2.value;
>
> which is working fine. But I would like to use the
> name of opener window, "Iamparentwindow" instead.
> Could you please help me?


Yes, stop wanting that. Then you will no longer care that it isn't going
to be possible.

Richard.

 
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
child jitter vs parent shaping vs child class-default on 871 and 1841 Robertas Cisco 0 02-23-2007 01:28 PM
Passing values from Child window with frameset to Parent window with frameset jimmyfishbean@yahoo.co.uk Javascript 0 07-11-2006 09:05 AM
Global Variables Between Parent and Child Documents (Windows) Patient Guy Javascript 1 09-16-2005 07:06 AM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM



Advertisments