5

Problem: Need to get a handle of an already opened javascript popup window (handle = window.open(…)) from its opener window, multiple requests later after its opener (parent) window has been refreshed and javascript variables reset.

For example, parent window could have javascript as follows:

<script type="text/javascript">
      var popupHandle;
      function openPopUp() {
            popupHandle=window.open('http://www.google.ca', 'popupTest');
            popupHandle.focus();
            return popupHandle;
      }
      // To get handle, need to reopen popup with same name as original (popupTest).
      function getPopUpHandle() {
            return openPopUp();
      }
      // If getting handle to close, open as small as possible and close so it’s not too noticeable.
      function closePopUp() {
            popupHandle=window.open('', 'popupTest', 'directories=no,location=no,menubar=no,status=no,resizable=no,scrollbars=no,titlebar=no,top=1,left=1,width=1,height=1');
            popupHandle.close();
      }
</script>

If you know of a better solution, please let me know.

How I am using it in my app: I have a list of images displayed on one side of the screen. On the other side I have a form that allows me to submit information based on the image. When the form is submitted, it attaches the image referenced.

When an image is clicked on, it opens in a popup.

When the form is submitted, the next image in the list should open in the popup. The popup could have been closed by the user.

4
  • Not an answer, but popups are bad, don't use them :) Try solutions like lightbox that might give your user a better experience.
    – marcgg
    Sep 22, 2009 at 17:49
  • The reason that a popup (which I think are bad as well) is used is so that the user can view the image in a separate window/monitor while filling in the form, using it as a reference. The images may need to be expanded to full screen at times to view the details.
    – CalvinTreg
    Sep 22, 2009 at 17:52
  • wouldn't lightbox fit your needs ? huddletogether.com/projects/lightbox2
    – marcgg
    Sep 22, 2009 at 17:54
  • I may not be looking at lightbox correctly. I need to be able to open an image, view it on one monitor, view the list of images and a form on the main page, and enter details of the opened image into the form. When I submit the form, the next image in the list should be opened in the same popup. With lightbox, as the images open, they cannot be moved to another monitor, and the page itself is hidden. Or am I missing some options with it?
    – CalvinTreg
    Sep 22, 2009 at 18:01

1 Answer 1

1

It's a bit of a kludge, but you could put a script in the opened window that attempts to call a function on its window.opener to inform the parent window of its existence.

So, the image-display window would have a function like

setInterval(function(){ 
   if(window.opener.registerChildWindow){ 
        window.opener.registerChildWindow(window);
   } 
 }), 100);

This would attempt call the registerChildWindow function on the parent window 10 times a second, as long as that function exists, no matter what page the parent window was on. I'm not entirely sure how to get a window handle out of an existing window (passing window was a guess), but that should at least be something to play around with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.