Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing multiple pop-up windows?

 
Sumithab Baskaran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread sounds like my blog posting from ages ago:
http://radio.javaranch.com/pascarello/2005/01/19/1106152877000.html

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic