Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Handle a window close event

Posted on 1998-08-14
4
Medium Priority
?
156 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

609 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