Connecting Tech Pros Worldwide Forums | Help | Site Map

Testing if a window is open?

laxmi
Guest
 
Posts: n/a
#1: Jul 23 '05
Is there a way to test whether a named window is open from a separate
window which may not have opened the window?
I have tried using:

if(windowname == null)
win = window.open(...)

This gives an error that windowname is undefined

if(window.windowname) doesn't work either (no error, but fails to
detect).

One alternative could be having win as a global Javascript variable.
Are there any other ways ?

Any help is appreciated.
Thanks
Laxmi

Richard Cornford
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Testing if a window is open?


laxmi wrote:[color=blue]
> Is there a way to test whether a named window is open from
> a separate window which may not have opened the window?[/color]
<snip>

No, the name given to a window as the second argument to the -
window.open - function has no representation in the browser's object
model. To test characteristics of a window you need to have a reference
to the corresponding window object. That reference is returned by the
call to - window.open - but if that window reference is not available
then there is no way of getting it short of calling the - window.open -
function and passing it the same name as the second argument. Pop-up
blockers not withstanding, re-calling - window.open - with the required
name as its second argument will result in a window being opened in the
event that a window with that name was not already open, and navigation
of that window if it was already open but the URL passed as the first
argument to - window.open - is not the URL of the currently displaying
page.

Richard.



Closed Thread