[thelist] javascript syntax

.jeff jeff at members.evolt.org
Sat May 11 02:53:01 CDT 2002


> From: Liorean
> > one common to all macs ?
> > what would that be?
> Try using:
> rd=/mac/i.test(navigator.platform)
>    &&(top.location='ns/index.htm');

what's wrong with simply testing for the substring "mac" in
navigator.platform like this?

if(navigator.platform.toLowerCase().indexOf('mac') != -1)

surely that'll have *much* better support than a regular expression.

indexOf() is available as far back as js1.0 which covers pretty much every
browser that's ever supported javascript.


whereas test() using a regular expression is only available as far back as
js1.2 which only makes up a marginal majority of browsers that support
javascript and even then, it's support (as well as support for regular
expressions in general) isn't consistent across those browsers that are
supposed to support it.


> If checks for any occurrence of the case insensitive
> text 'mac' in navigator.platform and if it exists
> changes the location string. If if doesn't exist, the
> AND (&&) works like a conditional short-circuiting and
> location isn't changed.

that doesn't make any sense to me at all, especially since the statement
after the && operator isn't even a conditional but an statement of
assignment (only one = in the statement).

> I'd also rethink the url. Some browsers use the relative
> url as root relative, some use if from the current path,
> and some doesn't expand it at all. I'd use an absolute
> url instead.

prefacing the location with a slash works in every browser i've ever

location.href = '/ns/index.htm';

good luck,


jeff at members.evolt.org

More information about the thelist mailing list