Normally you close a child window using an onUnload event handler in the body tag of the window that creates the child window, e.g.:
This will however close the child window even if you are just navigating to another page in your site. Keeping it open whilst still within your site is going to more difficult.
What you could do is use the onUnload event handler to trigger a checking mechansim in the child window that checks the location of the newly loaded document in the main window. If its on your own server then you'll be able to check the location, if its not on your server you'll not be able to check the location, and you'll get an error. You may be able to trap this error and thus close the window using self.close().
You'll need to trigger a checking mechanism that will allow a delay for the main window to change its location, so something like:
And then in the child window:
Note, that this has not been tested, and will need further work to make it robust. The onerror event handler was only introduced in Netscape 3 (I'm not sure about Internet Explorer). Also you may need to check if the location of the main window, although still on the same server, has not actually gone onto another site on the same ISP