File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Closing multiple pop-up windows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Closing multiple pop-up windows?" Watch "Closing multiple pop-up windows?" New topic

Closing multiple pop-up windows?

Sumithab Baskaran
Ranch Hand

Joined: Oct 29, 2004
Posts: 52
I have a page with multiple links and buttons. Fo example, let us condsider I have:
1) a href for "name". This hyper=link will open a pop-up window
2) a button called "lookup". This button will open a another pop-up window

When I hit the "save" button, I am checking for open-pop-up windows. here is the javascript code:
function checkPoppedWindows()
var ret = true;
if( winRef != null && !winRef.closed)
alertt("You are in the process of updating information.\nPlease finish
this process or close the window.");
ret = false;
return ret;

Question: this code works fine when I open one pop-up window, hit the "save" button without closing it.
But, when I open the "name" window, do not close it, open the "lookup" window also, do not close it and hit the save button: The alert message comes up and focusses on the "lookup" (the second) window. So I close it and then hit "save". Now ideally, it should alert me saying another window ("name" window)is open. But it does not. It "saves" the form. How do I fix this?

Thanks in advance!
[ July 21, 2006: Message edited by: Bear Bibeault ]
Pavan Keely
Ranch Hand

Joined: Jun 30, 2006
Posts: 62
You are updating the winRef everytime you open the window. Try to use an array of window references.

var winReferences = new Array();

so, when you open a window, winReferences[ winReferences.length ] =

and change your checkPoppedWindows function to something like,

Pavan Keely<br /><a href="" target="_blank" rel="nofollow"></a>
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Please use the UBB code tags when posting code to preserve its formatting.

Now ideally, it should alert me saying another window ("name" window)is open.

Why would you expect it to do this?

You've over-written the reference to the first window when you open the second. How is the code supposed to remember that long before it used to point to something else?

If you need to keep track of multiple references (to multiple windows) you'll need to do so in a construct that supports that.

So... what type of construct would allow you to keep track of more than one reference?
[ July 21, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
This thread sounds like my blog posting from ages ago:

I agree. Here's the link:
subject: Closing multiple pop-up windows?
It's not a secret anymore!