Does anyone know a better way to get a popup descriptor?

Problem: It is necessary to get the handle of the already opened javascript popup (handle = window.open (...)) from its open window, a few requests later after the window of its opener (parent) has been updated and the javascript variables reset.

For example, a parent window may 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 a better solution, let me know.

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

Clicking on the image opens a popup window.

When the form is submitted, the next image in the list should open in a pop-up window. The popup could be closed by the user.

+4
source share
2 answers

Refuse this site .. essentially reopen the window or use frames to track the descriptor.

+1
source

This is a bit kludge, but you can put the script in an open window that is trying to call a function on its window.opener to tell the parent window about its existence.

So, the image display window will have a function such as

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

This will try to call the registerChildWindow function in the parent window 10 times per second if this function exists, regardless of which page the parent window was on. I'm not quite sure how to get a window handle from an existing window (passing the window was a hunch), but this should be something to play with.

+1
source

All Articles