Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update child window from parent

Status
Not open for further replies.

ivpotter

Programmer
Jan 19, 2001
13
0
0
GB
Hi

I have successfully updated a section of innerHTML on a parent window from a child window but I am having trouble doing this the other way around.

Could someone please explain to me how to open a child window specifying a template document then update a portion of the HTML of that document.

ie something like ...

Code:
<SCRIPT>
  myWin = window.open(&quot;template.html&quot;, &quot;newWin&quot;)
  myWin.document.getElementById(&quot;updateBit&quot;).innerHTML = &quot;Hello&quot;
</SCRIPT>

where template.html looks like ...

Code:
<HTML>
<HEAD></HEAD>
<BODY>
<DIV ID=&quot;updateBit&quot;></DIV>
</BODY>
</HTML>

Any suggestions would be greatfully received.

Many thanks

Ivor
 
Hi Ivor,

did you ever get this figured out as this is exactly what I am trying to do - but so far with no success.

thanks


Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
No I didn't - I _think_ that it is a security feature and this activity is not allowed.

You could try something like getting the child to update itself based on the result of a &quot;question&quot; asked of the parent.

ie
parent sets a variable to the desired HTML
parent opens child window
child fetches HTML from parent
child updates the element with the data returned from the parent

This idea has only just occurred to me so it's completely untried.

Good luck

Ivor
 
Could you be a little more specific with what you are trying to do? I did't have any problem opening a window and updating the div tag using the code the you provided.

Code:
html>
<head>
<script>
function openChild()
{
  childWindow = window.open(&quot;child.htm&quot;);
  childWindow.document.getElementById(&quot;updateBit&quot;).innerHTML = &quot;Hello&quot;
}
</script>
<body>
<input type=button value=open onclick=&quot;openChild();&quot;>
</body>
</html>
 
How can you also CLOSE the child window FROM THE PARENT just like you opened it from the parent ... is that possible?

function closeChild()
{
......
}
 
Try using (based on my above code)
Code:
childWindow.window.close();
or
Code:
childWindow.self.close();
 
if the PARENT (parent.htm) opens a child window say ( win1.htm) ..... and then this child window opens another "sub-child" window say (win2.htm)


Can the PARENT (parent.htm) CLOSE the "sub-child" window win2.htm??????? If so, how?

Or is it that a window can ONLY be closed by the immediate window that opened it?
 
Here is an example where I close win2 from parent

parent.htm
Code:
<html>
<head>
<body>
parent window
<script>win1 = window.open("win1.htm");</script>
<input type=button value="Close Win1" onclick="win1.close();">
<input type=button value="Close Win2" onclick="win1.win2.close();">
</body>
</html>

win1.htm
Code:
<html>
<head>
<body>
win1
<script>win2 = window.open("win2.htm");</script>
</body>
</html>

win2.htm
Code:
<html>
<body>
win2
</body>
</html>

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top