[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to know that a window is still open
FYI and FWIW: I just tested window.name on the top-level window under
Windows 95, Windows 3.1 and Macintosh (68K) and all return an empty string,
not <undefined> or null. Can someone with a PPC Mac and various flavors of
Unix try this script and let me know the result when tested on a top-level
window?
alert (window.name);
If this is indeed a platform inconsistency we should investigate it.
-- Gordon
http://gmccomb.com/javascript/
At 08:55 PM 2/29/96 +0000, you wrote:
>
>> 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):
>>
>> <SCRIPT>
>** > 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
>> >with
>> >
>** > > 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
>
>for numeric
>
> 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:
>
> value+""
>
> or if I want it changed to a string I'll use
>
> value+="";
>
>And last but not least. The same as above but for numeric values I
>use:
>
>for compares:
>
> string*1 If I know the string will equate to a number.
> parseInt(string) or parseFloat(string) If I'm not sure.
>
>for assignment:
>
> 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
>JavaScript equating + to concantinate for expressions invoving a
>string variable or literal.
>
>I gotta stop drinking so much Diet Coke. I write too much.
>
-- Gordon
http://gmccomb.com/javascript/
--------------------------------------------------------------------
For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/