Solved

Handle a window close event

Posted on 1998-08-14
4
151 Views
Last Modified: 2008-02-01
On a HTML link, I call a javascript function to popup a window with some information in it. Because I want this window to be reloaded when I click on the same link, I close it, assign it to null  and I reopen a second one.  

This works great until the user press the window's close button(X). Thereafter, when he clicks on the link, javascript tell us that window of x name.close is not a function.  Because it's not me who closes the window in the code, I can't set this window var to null, and then, not tests it as closed.

Is there a solution for capturing a popup window closing event in javascript?  How can I know if a window object is valid or closed ?

I tried "if(x)", "If(x != null)", "if(x != "")", if(x != undefined) where x is the window's var.


========================================================
var winResult = null;
var winResult2 = null;

function LoadResult(File) {

      if (winResult != null)
            {
            winResult.close();
            winResult = null;
            winResult2 = window.open(File,'TITLE','width=450,height=400,top=50,left=50');
      }else{
            if (winResult2 != null)
                  {
                  winResult2.close();
                  winResult2 = null;
                  winResult = window.open(File,'TITL','width=450,height=400,top=50,left=50');
            }else{
                  winResult = window.open(File,'TITL','width=450,height=400,top=50,left=50');
            }
      }
}
======================================================

0
Comment
Question by:mhebert
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:bernfarr
ID: 1268305
Have you tried
  if (! winResult2.closed )
  {
    winResult2.close();
    etc.
  }

Note that the closed property is not supported under IE3.
0
 
LVL 1

Author Comment

by:mhebert
ID: 1268306
This doesn't work.  When the object is closed, it has no value and cannot be tested as closed.
0
 
LVL 2

Accepted Solution

by:
bernfarr earned 40 total points
ID: 1268307
How about
  if ( winResult2 && ! winResult2.closed )
  {
    winResult2.close();
    etc..
  }
0
 
LVL 1

Author Comment

by:mhebert
ID: 1268308
Thanks !  It works in NS3,NS4 and IE4.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question