aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Closing multiple pop-up windows?" Watch "Closing multiple pop-up windows?" New topic
Author

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
(code nclick=javascript:winRef=window.open(namde.do)
2) a button called "lookup". This button will open a another pop-up window
(code nclick=javascript:winRef=window.open(lookup.do)

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.");
winRef.focus();
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 ] = window.open(....).

and change your checkPoppedWindows function to something like,




Pavan Keely<br /><a href="http://keelypavan.blogspot.com" target="_blank" rel="nofollow">http://keelypavan.blogspot.com</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
This thread sounds like my blog posting from ages ago:
http://radio.javaranch.com/pascarello/2005/01/19/1106152877000.html

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing multiple pop-up windows?
 
Similar Threads
Problem with html:errors
form with target=opener
Reloading a parent window 1 after submit from window 2
Opening Windows
Enabling a button