Click to See Complete Forum and Search --> : Getting references to windows


aterry51
04-17-2003, 10:59 AM
Is there a graceful way to get references to windows?

In a home window, I open() another called "Commentary". Many pages
later I may need to do things to this second window. Is there a more elegant way to get a reference to it other than reopening it?
var win2 = open(someURL, "Commentary", ...) // same parameters
win2.doSomething

In the commentary window I'd like a close button that also resizes and moves the main window. I do NOT want to reopen the main window as there are various side effects. How do I get the reference to the main window? It is a JSP and was not opened in Javascript or with a specific name
-- mil gracias

_LOBO_
04-17-2003, 11:14 AM
can you put an example? LINK maybe to see

tim_gor
04-17-2003, 11:27 AM
I suppose this MIGHT be an elegant solution, though you'll have to test it out for yourself:

For clarity, let me just say that your main window is called MAIN, and your commentry window is called COMM

MPAGE1 is the page where you click to open the COMM window.
MPAGE2 is the page where you want to be able to do something to the COMM window.

Ok. MPAGE1 is loaded in MAIN. You click to open COMM.
COMM then opens MPAGE1 again in MAIN (i.e. reloading it)

many pages later, MPAGE2 is now in MAIN. To gain access to COMM, simply use the
"opener" reference

opener.dosomething(...)

For COMM to resize and do stuff to MAIN, you can also use opener, because COMM was opened by MAIN?

Well.. this is just a suggestion -- it may or may not work......!

tim_gor
04-17-2003, 11:34 AM
Another way, and perhaps an even more elegant method to use frames:

Organise your MAIN page so that it actually consists of 2 frames -- and for clarity call them TopFrame and MainFrame

TopFrame is your "controller", so to speak. It keeps a reference to the COMM window. For example, a global variable in the page in TopFrame called "commwin"

So to access COMM from any page in MainFrame, simply use
top.TopFrame.commwin

To access the main window from COMM, just use
opener.top

gil davis
04-17-2003, 12:04 PM
When you open the page called "Commentary", you can give it's opener a name.window.opener.name = "homeBase";
Once you have a name established, you can get a pointer to that window by using window.open().var myWin = window.open("", "homeBase");When you leave the URL parameter empty, the URL in the window with the specified name is not changed. If that window still exists, you have the pointer. If not, the side effect is that an empty window is created with that name.

aterry51
04-17-2003, 12:43 PM
Duh! I should have remembered opener as I use it further down the page.
But Gil's post is excellent. I would have never thought of naming the opener and didn't know you can "officially" use open() to get a reference that way.
Thanks all--this is great!