?
Solved

Handle a window close event

Posted on 1998-08-14
4
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 160 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

764 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