Solved

Handle a window close event

Posted on 1998-08-14
4
150 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Explain how this javascript function works 1 46
Interview question Javascript, database 12 57
HTML5 Get data in table rows 5 26
Help with removing item from Session Array 3 23
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

808 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