• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Closing multiple pop-up windows?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Everybody's invited. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic