View Full Version : test if window object still valid before using

06-02-2003, 12:20 AM
In my site design some links are opened in a re-used (i.e. named) window. Because some of the pages opened there rename the window (e.g. by explicitly setting self.name="other_name"), I "loose" access to that window for the next such link being followed. :mad:

To work around this, I rememer the window object when it's first opened and "push" my window name back into it. I use setTimeout() to setup this "name push" several times over the subsequent few seconds - but this creates a new problem: if the window is closed (X'ed out, not just minimized) then my push function generates an error because the window no longer exists when the code attempts mywin.name = "my_name". :(

Specifically, I this gives me an error: The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.

SO! Is there a way to test that a window object still refers to an available window before using it?


06-02-2003, 12:39 AM
x = window.open('.........

if (x && !x.closed) {....

Something odd about your re-naming 'push' but, whatever works...

06-02-2003, 01:04 AM
Cheese: I believe the post was about named windows, not window objects stored in a variable. The kind of window name you use in the target attribute, in the frames collection, in the second argument of the window.open method etc.

Slintz: You should be able to check for oWindowReference.closed. If it's true, then the window is no longer open and you need to open it again. That can be managed by an onclick on the link, for example.

06-02-2003, 01:17 AM
Thanks, cheesebagpipe - testing winobj.open() does the trick! :cool:

Also, liorean is correct that the kind of window I am using is the kind "you use in the target attribute."