Click to See Complete Forum and Search --> : test for window existence WITHOUT window.open()
slintz
07-12-2003, 02:44 PM
In my site design I want to coordinate two windows - one as a controller and the other as the viewer. To have them interact as designed, I need (in various situations) each to test for the existence of the other WITHOUT causing them to be created if they don't - as using window.open('', win_name) would do :(
TIA!
SlankenOgen
07-12-2003, 04:05 PM
If winB is a popup you can have in winA (also a popup)
if(opener.winB && opener.winB.open)
slintz
07-13-2003, 10:12 AM
Unfortunately, the opened-by relationship between the two windows is not guaranteed. What I'm looking for is a general way to test if a window is open (given a name) without causing it to be created if it doesn't exist.
SlankenOgen
07-13-2003, 10:52 AM
If, in the opener you write
winB = window.open(...
winB will not exist and be open unless the function to open it is called until the window is open.
look at this:
http://www.webreference.com/js/tutorial1/exist.html
here is an example:
----------------------------------------------------------------------
<script type="text/javascript">
<!--
var popupWin = window.open("check.htm","check"," height=400,width=200,left=50,toolbars=no,scrollbars=yes,resizable=yes");
//-->
</script>
<script type="text/javascript">
<!--
function test()
{
if(popupWin !=null && !popupWin.closed)
{
document.location.href = "start.htm"
}
else
{
document.location.href = "error.htm"
}
}
window.setTimeout("test()",200);
//-->
</script>
---------------------------------------------------------------------
Crossbrowser working script...
slintz
07-13-2003, 05:27 PM
The advice / suggestions have been useful (thank you!), but not quite on target for my needs. Perhaps my design is intractable?
Basically, I have a navigation window used to swim around in my site index. This will cause my navigation window to reload to the new index-node page each time a navigation link is followed. At any point, the user can choose to view a specific item of interest, which will show up in the (reusable) viewer window.
From the navigation window, the user might also pop up a site-search window, which provides links to items for either the viewer (specific results) or the navigation window (group results).
Thus, I have three windows: N, S, and V. N can target either S or V, while S can target either N or V. At any time, the user might dismiss either N or S (or V). When any of N, S, or V is targetted, if a so-named window is extant, it should be used, otherwise a new window is launched and used.
Given my (simple?) implementation of this design, I don't have persistent window-reference variables available. Navigation through the index pages will discard all variables in the "global" namespace (thus the use of popupWin suggested by man will not work).
Is there a way to preserve window object references across page loads? Should I be using FRAMESET's?
Ultimately, the trouble is that for a named window, window.open() can take a long time (several seconds). If only I could make them as quick as a "_blank"... (Any ideas?)
SlankenOgen
07-14-2003, 04:02 AM
You could try using a frameset with one frame only 1px high (or wide) and put your variable there. You could use a variable myPopupOpen = true/false, and set it to the appropriate value.
Then use top.frames.[0].functionName to make the variable = true/false and use
if(opener.parent.frames[0].myPopupOpen == true)