Solved

Handle a window close event

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now