Forum Moderators: open

Message Too Old, No Replies

Checking if a window is open...

Can it be done somehow?

         

Wertigon

8:21 am on May 11, 2004 (gmt 0)

10+ Year Member



Hey all, sorry to bother you again, but I can't seem to find this anywhere on the web...

What I want to do is to check if a popup-window is already open, and if so, it shouldn't load up a new version of the same popup. Yes, I know it can be done simply by just giving the same name to the window. The trouble is that this particular window can be named as either name1 or name2 (long story).

So is there a way to get the value of the window? Something along the lines of

if ( window.name == name1 ) { [...] }
else if ( window.name == name2 ) { [...] }

Of course, this is just pseudo code. Help would be greatly appreciated, as always. =)

Rambo Tribble

1:15 pm on May 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you thought about addressing the window through the parent-child hierarchy?

Wertigon

5:38 pm on May 11, 2004 (gmt 0)

10+ Year Member



How would I go about addressing that? I'm pretty much a newbie at Javascript (although not a newbie at programming), so I'm quite possibly missing a thing or two regarding it...

Isn't there some array or something like, windows[x] or documents[x] that I then can spin further upon?

Rambo Tribble

5:18 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most of the DOM is involved with operating on a document within a window. It is also possible to address windows up the parent-child hierarchy, but I'm not aware of a way to address a child window from the top window through the DOM. Have you considered opening the window by assigning it to a variable? See if this helps:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Window hijinks 05-12-04</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var winx=false;
</script>
</head>
<body>
<p>
<a href="javascript:winx=window.open();top.focus();">Open a window</a>
</p>
<p>
<a href="javascript:winx.document?alert('win open'):alert('no win');">check win</a>
</p>
</body>
</html>

Bernard Marx

5:27 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't tested Rambo's. It seems OK as long as winx being closed doesn't mean that it returns 'undefined' or null. If so, we'll get an error if we try to go further.

There is a closed property that could do it:
[webreference.com ]

Wertigon

8:01 am on May 13, 2004 (gmt 0)

10+ Year Member



Hmm... The only problem with that is that it would require the base HTML page where the popup was loaded from to be intact, which doesn't suit my purposes... Is there any way to do it if the mother window is closed, or redirected to another page, or whatever?

Bernard Marx

11:23 am on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wouldn't like to say it's impossible, but it sounds tough.
Perhaps you could have the windows pass variables to each other - on unload maybe.

Rambo Tribble

1:12 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the opener page is being closed before the child, you will need to have your code run in the child. If it is necessary to display content from another site in the child window, you might want to investigate HTML iframes.

Passing variables between pages is usually handled with cookies.