View Full Version : Close popup when I reload parent

12-16-2005, 06:17 AM

I have read 50 or so posts and keep rewriting (piecing code together) to accomplish one of two things.

Either 1: Pop open a small window onunload which checks to see if it is on the same domain as the parent window and if so, closes itself.


2: Pop open the small window onunload. When the parent reloads it closes the popup (onload=close the child window).

I can get the popups to open just fine, but don't know how to close them when the parent reloads.

This loads the popup onclick or onunload:
<script language="JavaScript" type="text/JavaScript">
function MM_closeBrWindow(theURL,winName,features) { //v2.0

I've tried amongst 20 other things:
<body onload="window.close('popup.html')"> in the parent window.

and in the popup

<script type="text/javascript">
function {
if parent.window.location = "http://www.whatever.com/parent.html";

Thanks for any ideas.

12-16-2005, 02:33 PM
Ok, check this out and see if you can make it work with what you have:

This would go in the <head></head>:

<script language="JavaScript">

var popupWindow;

function openWin()
popupWindow = window.open('http://www.google.com', 'ChildWindow');

function closeWin()


And you would call closeWin() to close the window in your <body>'s onload event handler:

<body onload="closeWin();">

The main difference in this code and what you're probably using is that I made popupWindow a global variable. Then inside openWin() I set that variable to window.open, which then gives you a kind of handle on that window. Then all you need to do to close it is call closeWin().

Hope this helps.