...

View Full Version : How do I close the parent window with a child window.



HAOS
08-03-2002, 10:54 AM
I have used a javascript code to have a brand new window pop up on load which minimizes itself while the popup window says visible. The parent window also has a code where it will close the loaded pop-up window if it closes itself. I would like to be able to close the parent window with a button on the new pop-up window so that both windows are closed at the same time. Is that possible?

Thank you for your help.

-Haris B.

Spookster
08-03-2002, 03:36 PM
<a href="javascript:opener.close();">Close Parent Window</a>

Note that trying to close the parent window will generate an alert telling the user that the web page is attempting to close their main browser window and then ask them if they wish to proceed. That is a security feature built into the browser so no getting around it.

HAOS
08-03-2002, 10:59 PM
I just tried it it doesn't seem to work.
It doesn't close any windows at all.

Any other ways of doing it?

-Haris B

Spookster
08-05-2002, 05:42 PM
Let's see your code.

beetle
08-05-2002, 10:10 PM
Not so fast! Check this out! :D

http://aspalliance.com/peterbrunone/impossible.asp

Spookster
08-06-2002, 12:09 AM
Originally posted by beetle
Not so fast! Check this out! :D

http://aspalliance.com/peterbrunone/impossible.asp

Interesting. The article is misleading though. You can close the parent window without changing the status of the parent window. It will just prompt the user to close it. But utilizing their technique that parent window can be closed without the prompt.

Note: If you are doing this you will irritate the users when you close their parent window unless of course it is a window that you opened beyond the users first window.

Anyways to summarize it works as follows:

Code that goes inside the popup window:




<html>
<head>
<title>Your Popup window</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="javascript:opener.close();">Close Parent Window</a>
</body>
</html>


Code that goes in your parent window:




<html>
<head>
<title>Parent Window</title>

<script language="javascript">
<!--//
function popup(url,windowname,w,h,x,y){
popwin = window.open(url,windowname,"resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
}

window.opener = top;
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="javascript:popup('popup.html','mypopup','335','255','50','50');">Open Popup Window</a>
</body>
</html>

HAOS
08-06-2002, 03:59 AM
:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum