Click to See Complete Forum and Search --> : Opening a new window, onLoad issue


jovialjonny
06-03-2003, 09:23 AM
Hi,
I am trying to open a new window from a parent window containing an HTML page I wrote. I am doing this via:
viewer = window.open("multiviewer.html");

Then (in the parent window) I am trying to append some items to the body of the newly opened page like so:
viewer.document.body.appendChild(topContainer);

The problem is it doesn't recognise the viewer.document.body because that script is executing before the new page fully loads i.e.the body does not exist yet.

Does anyone know how I can solve this? I was thinking of putting all of it in an onLoad function but I don't really know how I could do this or if it would work.

Any suggestions at all would be appreciated.

Gollum
06-03-2003, 09:42 AM
In your multiviewer.html you could call back to the parent when your're ready...

<body onload="window.opener.loadChild(document);">



then in your main window...

var topContainer; // set some time ago
function loadChild(doc)
{
doc.body.appendChild(topContainer);
}

jovialjonny
06-03-2003, 09:59 AM
Originally posted by Gollum
In your multiviewer.html you could call back to the parent when your're ready...

<body onload="window.opener.loadChild(document);">



then in your main window...

var topContainer; // set some time ago
function loadChild(doc)
{
doc.body.appendChild(topContainer);
}

Ya that might work...I didn't realise you could access javascript functions in other pages like that (window.opener.loadChild(document)).

I may actually be making life more difficult than it needs to be. All I want to do is get a variable from the opener page into a function on the child page. Can you do that?
At a guess I'd say:
viewer = window.open("multiviewer.html)
viewer.addToViewer(some_string)
(addToViewer is a function in the multiviewer.html's javascript file)

Is that possible? If so is that syntax correct? I cant find much about these kind of parent/child relationships anywhere else so any insights are really helpful.