PDA

Click to See Complete Forum and Search --> : closing parent window when child opens


lenin
Mar 2nd, 2001, 07:34 AM
Hi,
I have been trying to close a parent window when it spawns a child using the opener.close method, but have had no success. When I try to run the javascript command in the child window it reports unterminated string or runtime error. Can anyone see the problem or provide source to do this?

Source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>

<HEAD><TITLE>New Window Test</TITLE>
<FORM>

<BODY>
<SCRIPT language=JavaScript>
<!--
function newWin()
{


pageContent = "<HTML><HEAD><TITLE>";
pageContent += "Close Parent Test</TITLE>";

pageContent += "</HEAD><FORM><BODY>";


pageContent += "<script langauge='JavaScript'><!-- opener.close(); //--></script>";


pageContent += "</BODY><FORM></HTML>";



cardWindow = open("","cardWin","width=450,height=350,resizable=1");



with (cardWindow.document)
{
open();
write(pageContent);
close();
}

}

//-->
</SCRIPT>

<INPUT type=button value="New Window" onclick=newWin();>

</BODY></FORM></HTML>

Mar 2nd, 2001, 10:45 AM
Try this code for closing your windows.


<script language="javascript">

function closeWin()
{
window.close();
};

</script>

<A HREF="javascript:closeWin();"
onMouseOver="window.status='close the Window';return true";>close Window</A>

lenin
Mar 2nd, 2001, 10:58 AM
Matthew will this not just close the current window. I want a parent to open a new window, and when the new window opens the parent closes.

Thanks

Lenin.

harsoni
Mar 16th, 2001, 12:34 PM
This is impossible i guess...

sonia

Mark Sreeves
Mar 19th, 2001, 05:16 AM
Originally posted by harsoni
This is impossible i guess...

sonia

Don't guess!;)




Put the following in the child:

<script langauge="JavaScript"><!--
opener.close();
//--></script>



Although you'll need to make sure that the opener has been defined for browsers that don't have it by default, by placing the following in the parent:

<script language="JavaScript"><!--
msgWindow=open('',window,'resizable=no,width=200,height=200');
msgWindow.location.href ='apage.html';
if (msgWindow.opener == null) msgWindow.opener = self;
//--></script>



Note, that this will likely prompt the user for confirmation before closing the window.

harsoni
Mar 19th, 2001, 03:35 PM
Hey Mark,
That is good you showed in fact we can close the parent window from the child window...but i have a problem how do u avoid the message box that pops up???


Sonia

Mark Sreeves
Mar 20th, 2001, 02:18 AM
I had a feeling that question would be next! ;)

this might help:
http://developer.irt.org/script/366.htm

I haven't tried it though



(my last post came from www.irt.org as well)