Re: window closing

by Nate Harel <nharel(at)nettech-services.net>

 Date:  Sat, 11 May 2002 10:36:47 -0400
 To:  hwg-techniques(at)hwg.org
 References:  peel3
  todo: View Thread, Original
That was the answer.

Thanks to all.

Nate

At 5/10/2002 11:18 PM, Larry Coats wrote:
>Nate Harel wrote:
>
>>According to the javascript book (O'Reilly)
>>"Only windows opened by Javascript can be closed by Javascript..."
>>That's what I want to do.
>>The code I am using is
>>----------------------
>
>>function openit(){
>>window.open("test1.html","mywindow","width=400,height=500")
>>}
>>function closeit(){
>>  close("mywindow");
>>}
>
>
>
>The argument to the close() method is a window object, not the name you've 
>given to the window. The open method returns a reference to the window 
>object, and you'll need to save that in a global variable. In your closeit 
>function, you'll want to test whether the global contains a window 
>reference, and if so, whether the window is open. And after you close it, 
>you'll want to get rid of the reference just to let things get cleaned up. 
>So something like this:
>
>var oWindow = 0;    // Global variable defined outside of any function
>
>function openit() {
>   oWindow = window.open (...);
>}
>
>function closeit() {
>   if (oWindow && !oWindow.closed) {
>     close (oWindow);
>   }
>   oWindow = 0;
>}
>
>
>Larry Coats
>
>
>


                 ----------------------------------
                             Nate Harel
                         NetTech Services
                           56 Pickering Street
                   Needham, MA  02492
                       Tel:  1-781-559-8176
                   Toll Free: 1-877-567-8936
                      FAX:  1-877-567-8936
                 Email:  nharel(at)nettech-services.com
                      www.nettech-services.net
                      www.nettech-backup.com
                      www.nettech-hosting.com
                 ----------------------------------

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.