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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Child, Refresh Parent 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
just need a simple way to close a child window and refresh the parent window with one click on the child, can be on an anchor tag or via a form....
 
the child window contains the following:

<html>
<head><title>Child Page</title></head>
<script language=&quot;jscript&quot;>
var pWin
function setParent(){
pWin = top.window.opener
}
function refreshParent()
{
pWin.refresh()
window.close();
}
</script>
<body onload=&quot;setParent()&quot; onunload=&quot;refreshParent()&quot;>
<input type=&quot;button&quot; value=&quot;CloseChildWindow&quot; onclick=&quot;refreshParent();&quot;/>
</body>
</html>

 
When you open the child window, use the command:

window.open('URL', windowName)

then you can use a function to close:

function closeWindow()
{
windowName.close()
window.location = URL to Refresh
}


Hope this helps,

Scarecrow
 
ok here's what I have:
in parent window I have:

<script>
self.name=&quot;main&quot;;

.....

</script>

in child I have:
function closeMe() {
this.close();
main.location=&quot;URL&quot;;
}


but I get this error:
Error: 'main' is undefined

is the parent window not getting named???
 
You want to try and close the child from the parent and then redirect the parent. You are closing the child from the child and trying to redirect the parent.

Skark166 seems to have the option that would work, have you tried it?
 
that is what I am trying to do though ??? I want to close the child from the child and refresh the parent with the same click - one click IN THE CHILD -> close the child and refresh the parent... and yes if you'll compare the code- that is the one I have tried...
 
ok I did an alert test on my parent window and it is getting named correctly but something with the resfresh script is not right.... I tried window.main.location but then I get this error:

&quot;window.main&quot; is null or is not an object
 
child.htm
<script>
function closeWin(){
mainURL = window.opener.location.href
window.opener.location = mainURL
self.close()
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
ok- now here is amother issue... I have the parent opening a child, that child then links to a &quot;sibling&quot; ... how can I close that sibling and refresh the original parent??
 
I believe that the window.opener object will still hold the same information. Have you tried to see if the code still works?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
I have a parent openning a child which in turn opens a child. The child closes ok but when the parent is reloading I get a message from the browser that states that I need to resend the page to the server.

When I resend the page all of the changes are displayed on the parent that I would expect. How can I get rid of the &quot;Resend&quot; message?

Here is the code:

window.opener.location.reload();
window.close();


I have even tried:

window.opener.location = window.opener.location.href;// + &quot;&dspLayoutName=&quot;;
window.close();

TIA
Nate
 
Is the parent window a form handler? It sounds like it is. In that case, remember that the form would have to be resubmitted. You may be better off creating a hidden form that holds all of the initial values and then resubmitting the form from the popwindow....

main.htm
<form name=&quot;hiddenForm&quot; action=&quot;main.asp&quot;>
<input type=hidden name=&quot;field1&quot; value=&quot;<%=val1%>&quot;>
<input type=hidden name=&quot;field2&quot; value=&quot;<%=val2%>&quot;>
<input type=hidden name=&quot;field3&quot; value=&quot;<%=val3%>&quot;>
</form>

child.htm
<script>
function closeWin(){
window.opener.hiddenForm.submit()
self.close()
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top