• 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

how do i get window reference without re-opening?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want my users to be able to click on a link, and if the specified window has already been opened, I want to change focus to that window, rather than re-opening the page.
Here is the code that I have:

function openAppWindow(url, target) {
newwindow = window.open(url, target, 'width=1024,height=768,resizable=no,scrollbars=yes,status=no,toolbars=no');
newwindow.focus();
}

However, I want to get the window reference without having to call window.open. The reason is that this is an application, and user could be three screens in when they go out and do something else in another popup window. Then when they want to come back, I'd like them to be able to click on the link to go back to the popup (instead of requiring them to find the appropriate window in their task bar). If I do window.open, then it will run the first action again, and they'll have to click through a few things again to get back to where they were.

So, I'm wondering, is it possible to get a handle on the window reference without calling the window.open method? If window.open can find the appropriate window using the target, I would think I'd be able to, too, but I haven't been able to find anything that says how to do it. I have seen several places that have you store the reference in a var, but I could have several popup windows open at one time, and I don't think it's very reasonable to require me to have a separate variable and method for each possible popup in my application (i.e. different functions do not share the same popup window; each function has its own window so you can do multiple things at a time).
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Eric
 
Sheriff
Posts: 67747
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

Originally posted by K Dombroski:
I don't think it's very reasonable to require me to have a separate variable and method for each possible popup in my application



That's the type of thing that a Map is really good for. And while JavaScript doesn't have a native Map implementation, the dynamic, associative nature of the Object, is a pretty good approximation.

For example:



Of course, everything disappears if the user refereshes the parent page...
 
K Dombroski
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bear! Would it be possible to store that in the session somehow so it does not get lost when the user refreshes/navigates away and then navigates back?
 
Bear Bibeault
Sheriff
Posts: 67747
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
Afraid not. And even if you could, the handles would be meaningless to the new page (and any references to opener in the child windows would also be invalid).
 
K Dombroski
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks much for the help! At least now, if my manager says he wants it to do that, I can tell him that it can't be done. Thanks again!
 
Bear Bibeault
Sheriff
Posts: 67747
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
Web app designs that depend upon child and parent windows staying in synch are rather fragile.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic