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 a child window and refresh the parent 1

Status
Not open for further replies.

guineamation

Programmer
Jan 29, 2002
58
IL
Hi,
I have a parent window who opens a child window:

function openPicEdit(imgID)
{
var dest="inc_picEdit.asp?imgID=" + imgID;
window.open(dest, "win_Image", "toolbar=no,status=no,scrollbars=yes,height=400,width=400,resizable=1")
}

on action the child window calls a function in parent window that suppose to close the child and refresh the parent

function RemovePic(cod) {
var str = submit.frm_Text.value;
for (i=1; i<=10; i++) { str = str.replace(cod,'') }
submit.frm_Text.value = str;
win_Image.close();
window.location.reload();

}

the child window will not close and the parent window is not reloading...

any ideas?
thanks in advanced....
 

You need to return a handle from the window.open call to be able to reference the popup. Somehting like this:

Code:
winHandle = window.open(dest, 'win_Image', 'scrollbars,height=400,width=400,resizable');

and then use this to close it:

Code:
winHandle.close();

As for not reloading... are you sure that the function is being called? Try putting an alert at the top of it.

Hope this helps,
Dan


 
Thanks for the quick response, the function wasn't being called as u suspected...
i'm still having some problems with the close child thing.
does it matter if i reload the page before or after i try to close the child?
and about the windowHandler... it have to be a global var right?
 

Yes - the window handle has to be global, IF you are not using it within the function that you assigned it.

You cannot close the child [from the opening page] if you have refreshed the opening page, as the window handle will no longer be valid.

Hope this helps,
Dan



The answers you get are only as good as the information you give!

 
no go with the close window, this is the script structure on the parent window:

<script language="JavaScript" type="text/JavaScript">
<!--
var winHandle

function RemovePic(cod) {
var str = submit.frm_Text.value;
for (i=1; i<=10; i++) { str = str.replace(cod,'') }
submit.frm_Text.value = str;
winHandle.Close();
window.location.reload();
}

function openPicEdit(imgID)
{
var dest="inc_picEdit.asp?imgID=" + imgID;
winHandle = window.open(dest, "win_Image", "toolbar=no,status=no,scrollbars=yes,height=400,width=400,resizable=1")
}
//-->
</script>

if i try to reload the page before closing the child, the parent is reloading but the child is not closing as u explaind before.
but when i try to close the child before reloading, nothing happends...
 

You need a lowercase "c" on "close". JavaScript is case-sensitive.

Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top