Click to See Complete Forum and Search --> : Hanging on to window.open() values


FG1
11-26-2002, 12:54 PM
Is it possible to retain values returned from window.open() after a submit?

ie (briefly)

var wFred = window.open(some parameters);

I can access the window I've opened by using wFred up until the first window's form is submitted. After that I can't. Is there a way around this?

Many thanks

FG

(edited for typos!)

gil davis
11-26-2002, 04:12 PM
If the page is refreshed or replaced by the subit action, you lose the data space of the previous "session". To reestablich connection with the window, use the name attribute when you open it. If a window with the specified name parameter exists, window.open() will reuse that window. If not, it opens a new window and gives it that name.

var wFred = window.open(url, name, params);

If "url" is omitted (""), the window will not change contents.

This will also give you a handle to a window opened by a link with a target parameter (target="somename").

FG1
11-26-2002, 04:48 PM
Gil

Thanks for that. I was aware that I could do that but I'm not sure I can get what I want done using it. But if that's the only way I will just have to try.

Perhaps my question should have been: can you detect whether the child window has been opened?

Thanks for your help.

FG

gil davis
11-27-2002, 06:19 AM
Originally posted by FG1
Perhaps my question should have been: can you detect whether the child window has been opened?

There are two things to test for: 1) does the pointer exist and 2) is the window already opened.


var wFred = null; // establish variable
...
if (wFred) // if not null
{if (!wFred.closed) // if already open
{ // do what you need to do
}
}
...

FG1
12-03-2002, 03:59 AM
I got round the problem another way. The child window sets a field in the parent to "1" whenever it is open, and to "0" when it gets closes. This seems to work quite well.

Let me know if anyone needs a fuller explanation.

FG