[thelist] javascript syntax

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


loriean,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 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.

http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm#119689
5

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.

http://developer.netscape.com/docs/manuals/js/client/jsref/regexp.htm#119412
8

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> 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
encountered.

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

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/





More information about the thelist mailing list