[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to know that a window is still open
> Few days ago I asked how to recognize that a given window is
> the topmost window
There have been a few posts in reply to this. Here's mine.
Given the following:
> Weird. The following works for me (I'm using Windows
> 95, BTW):
** > if (window.name == "")
> alert ("top level window")
and the following:
> >Off the top of my head: If you open the window and
> >pass it a name, like this:
> > window.open ("blah.html", "win1");
> >then it will have a name. You can test for the name
** > > if (window.name !="")
> > you're in the top window
> >But, it doesn't work. I tried to display window.name
> >(exactly in this example window.win1) with alert and
> >always I'v got '<undefined>' value.
I wouldn't trust versions of Netscape across all platforms
to act the same. Some might return "", or undefined, or
null in some cases. Changing the marked line of the
script in the first example to:
if (window.name+"" == "")
and the marked line of the second example to:
if (window.name+"" !="")
might provide better compatibility across platforms. To convert any
unexpected <undefined> and null to usable values I use the following:
for string (as above)
string+"" for compares and string+="" for assignment
value+0 for compares and value=+0 for assignment.
If I need to compare a numeric value against its string counterpart,
temporarally express it as a string, or need to use it with indexOf ()
and do not want to change the original value I will use:
or if I want it changed to a string I'll use
And last but not least. The same as above but for numeric values I
string*1 If I know the string will equate to a number.
parseInt(string) or parseFloat(string) If I'm not sure.
string*=1 If I know the string will equate to a number.
string=parseInt(string) or string=parseFloat(string) If I'm not sure.
Note: 'string' in the last example becomes numeric. I'm just
reusing the vaiable 'string' rather than creating a new one.
I'm sure everyone knows the * verses + in the above example is due to
string variable or literal.
I gotta stop drinking so much Diet Coke. I write too much.
For help about the list, please send a message to 'email@example.com'
with the message body 'help'. To unsubscribe, send a message to