Distinguishing Mac OS X Versions

W

william.oram

Is there a way to use JavaScript to distinguish between Mac OS X 10.4
and earlier OS X versions like with Windows? browserType.UserAgent
outputs the following on a 10.4 machine, which (to me) says nothing
about the specific OS:

mozilla/5.0 (macintosh; u; ppc mac os x mach-o; en-us; rv:1.8.1.3)
gecko/20070321 firefox/2.0.0.3

Thanks,
Will
 
T

Thomas 'PointedEars' Lahn

Is there a way to use JavaScript to distinguish between Mac OS X 10.4
and earlier OS X versions like with Windows?

There is no such way, not even with Windows.

http://pointedears.de/scripts/test/whatami
browserType.UserAgent

Never heard of that. Do you mean navigator.userAgent?
outputs the following on a 10.4 machine, which (to me) says nothing
about the specific OS:

mozilla/5.0 (macintosh; u; ppc mac os x mach-o; en-us; rv:1.8.1.3)
gecko/20070321 firefox/2.0.0.3

Try feature detection instead.


PointedEars
 
J

Johannes Schmidt

Is there a way to use JavaScript to distinguish between Mac OS X 10.4
and earlier OS X versions like with Windows? browserType.UserAgent
outputs the following on a 10.4 machine, which (to me) says nothing
about the specific OS:

mozilla/5.0 (macintosh; u; ppc mac os x mach-o; en-us; rv:1.8.1.3)
gecko/20070321 firefox/2.0.0.3

There is some logic you can apply to the Safari version number to
determine the OS version. With Firefox you won't be so lucky. For
Firefox the best you can determine is whether it's an Intel processor
(and therefore >= Tiger) or not. Here's a wiki page (with a long URL)
that someone with the same need as you created:
http://tinyurl.com/2b68bw

You need to filter out the others in this microverse who'll tell you
that you can't rely on the user agent. They don't live in the real world
and have the luxury of telling their employers "NO" to any request to
produce code that would require looking at the user agent string. Those
of us that have to live with reality know that the user agent is the
best info we've got and does the job as well as we need it to. I've
tried staying out of the threads they had about it because they were
just back and forth amongst themselves. When I see them force that
diatribe on an unsuspecting noob like yourself then I don't want to let
them convince you (with the two replies so far) that you can't do
anything. You can do something and it's better than nothing. I'm
assuming you have a genuine need for it and can't do feature detection.

</js>
 
T

Thomas 'PointedEars' Lahn

Johannes said:
You need to filter out the others in this microverse who'll tell you
that you can't rely on the user agent. They don't live in the real world
and have the luxury of telling their employers "NO" to any request to
produce code that would require looking at the user agent string.

Are you being deliberately obtuse or are you just mindboggingly incompetent?

The correct answer is: *No*, you *can* *not* rely on the User-Agent header
or on navigator.userAgent for that matter. Nor are you required to, there
are *far better* means to facilitate graceful degradation.

We have discussed the pitfalls of browser detection at great length here,
there is even a section about it in the FAQ Notes.
Those of us that have to live with reality know that the user agent is the
best info we've got [...]

Tell me, how is the weather in your parallel universe?


PointedEars, with a fitting random sig
 
J

Johannes Schmidt

Thomas said:
Are you being deliberately obtuse or are you just mindboggingly incompetent?

Don't pretend you haven't already made your mind up which it is.
The correct answer is: *No*, you *can* *not* rely on the User-Agent header
or on navigator.userAgent for that matter. Nor are you required to, there
are *far better* means to facilitate graceful degradation.

How does graceful degradation come into this topic? The OP didn't say
anything about wanting to facilitate graceful degradation. What are
these better means anyway? It seems that most of the people here just
want to say "[insert anything here] is not possible, don't try and do
it" and never provide a working alternative.

You'd all be great assets in projects that break new ground I'm sure.
Sorry - can't be done. Can't do it. No. No. No. Go away and stop asking
me. Real pioneer spirit. What people that come here need is something
that will work.

What I imagine the OP wants to do is offer a different program download
based on the OS. So how does feature detection help there?

</js>
 
W

william.oram

There is no such way, not even with Windows.

http://pointedears.de/scripts/test/whatami


Never heard of that. Do you mean navigator.userAgent?

Oops, sorry. Copied and pasted the wrong snippet. :p

It is true that userAgent can be spoofed to become near anything. In
the vast majority of cases, though, it likely is legit, so it seems
like checking userAgent is reasonable. The browser/feature check code
I'm modifying is supposed to prevent uncertifiable behaviour. If users
want to lie their way into a system they make inoperable, well...sucks
to be them.
Try feature detection instead.

Were I writing this from the start and knew precisely what stylistic
web elements were needed, that would be a wise move. Sadly, it's hand-
me-down code, and it's gotta be browser/OS detection or nothing.
 
T

Thomas 'PointedEars' Lahn

Oops, sorry. Copied and pasted the wrong snippet. :p

It is true that userAgent can be spoofed to become near anything.

It is spoofed already and that is not going to change in the foreseeable
future. Granted, UAs for Mac are not that likely a target; still a possible
one.
In the vast majority of cases, though, it likely is legit,

It's not.
so it seems like checking userAgent is reasonable.

So it *seems*.
The browser/feature check code

Wait a minute. A browser check is not a feature check, which is the cause
of the problem. Are you saying you use feature-testing code already? If
yes, would it not be better to find out if there was a way to improve it?
I'm modifying is supposed to prevent uncertifiable behaviour.

It would help a great deal if you wrote what that so-called "uncertifiable
behavior" was before you readily jump to the conclusion that there is no
other way than browser detection. There is always a possibility that you
have overlooked something.
If users want to lie their way into a system they make inoperable,
well...sucks to be them.

You are forgetting that it is mainly not the users who lie, but the UAs
they use. Because their vendors want to sell them. That has not changed
since the browser wars and is not going to change in the foreseeable future.

You are not proposing that users use a different UA or a different (mobile)
device just to have a look at your fascinating Web sites, are you?
Were I writing this from the start and knew precisely what stylistic
web elements were needed, that would be a wise move. Sadly, it's hand-
me-down code, and it's gotta be browser/OS detection or nothing.

Unlikely.


PointedEars
 
G

Gregor Kofler

Johannes Schmidt meinte:

[utter crap]

But what can you expect from somebody of the Jerusalem School of
Synoptic Research who ventures into the realm of client side scripting...

Gregor
 
D

David Mark

There is some logic you can apply to the Safari version number to
determine the OS version. With Firefox you

What sort of logic would you apply to an arbitrary sequence of
characters to determine anything but their character codes and length?

won't be so lucky. For
Firefox the best you can determine is whether it's an Intel processor
(and therefore >= Tiger) or not. Here's a wiki page (with a long URL)
that someone with the same need as you created:http://tinyurl.com/2b68bw

You need to filter out the others in this microverse who'll tell you
that you can't rely on the user agent. They

Why? They are right.

don't live in the real world
and have the luxury of telling their employers "NO" to any request to
produce code that would require looking at the user agent string. Those

In other words, because you don't understand browser scripting, you
stick your employers with unreliable code.
of us that have to live with reality know that the user agent is the
best info we've got and does the job as well as we need it to. I've

The best info for what job? Writing incompetent scripts?
tried staying out of the threads they had about it because they were

You would do well to stay out of them. You have no idea what you are
talking about.
just back and forth amongst themselves. When I see them force that
diatribe on an unsuspecting noob like
yourself then I don't want to let
them convince you (with the two replies so far) that you can't do
anything. You can do something and it's better than nothing. I'm

I feel the same way when I see clueless developers spreading
misinformation.
assuming you have a genuine need for it and can't do feature detection.

And why couldn't they do feature detection? Features can always be
tested. Browsers cannot and even if they could, writing script for a
specific build or a specific browser on a specific OS is madness.
 
D

David Mark

Don't pretend you haven't already made your mind up which it is.

I know I have.
How does graceful degradation come into this topic? The OP didn't say

A better question is why did you come into this thread? You clearly
don't understand the discussion.
anything about wanting to facilitate graceful degradation. What are
these better means anyway? It seems that

You've been told more than once. Go back and re-read the posts in
this thread.

most of the people here just
want to say "[insert anything here] is not possible, don't try and do
it" and never provide a working alternative.

Utter nonsense unless the question is along the lines of "I want to
detect Netscape." More like "[insert anything here]" is stupid and/or
unnecessary, so try to do it another way. Whatever the method, do not
employ the user agent string to create the illusion of a solution.
You'd all be great assets in projects that break new ground I'm sure.

When you break new ground with browser detection, get ready to bury
your credibility (and perhaps your career) in the resulting hole.
Sorry - can't be done. Can't do it. No. No. No. Go away and stop asking

It seems you are frustrated about something. Okay, what are you
trying to do?
me. Real pioneer spirit. What people that come here need is something
that will work.

What they certainly don't need is "advice" such as yours.
What I imagine the OP wants to do is offer a different program download
based on the OS. So how does feature detection help there?

Not a whit. Nor does browser detection, which never helps anything as
it is impossible.

Here are two solutions to the problem:

1. Present the user with a select element that lists the operating
system choices. As long as the user knows what OS they are using,
they will download the correct program.

2. Parse an arbitrary string and determine the "likely" OS based on
some Wiki article and use the resulting "information" to automate the
choice. You just saved the user two seconds, but if your "logic" is
not infallible (which it obviously can't be), you run the risk of
sending them the wrong software, which could waste several minutes (if
not hours.)

Which do you think your customer and/or employer would prefer?

The lesson is that feature detection is not a solution for everything,
but browser detection is never a solution for anything.
 
D

David Mark

David Mark said the following on 8/7/2007 9:05 PM:



The window.external was solved and I am still hopeful that feature
detection can solve my createTextNode issue with IE. Until it is, I have
to disagree with the assessment that features can always be tested for.

Right. They can always be tested for, but the results won't always be
helpful. A better way to put it is that feature testing can't solve
everything, but browser detection solves nothing as results from that
method are always unreliable.

What is the createTextNode issue in IE? For script blocks?
Although I have a work around for it, it would be nice not to have to
kludge around a flaw in IE.

I have to figure the workaround solution does not involve th UA
string. Regardless, as you say, it would be preferable if a reliable
feature test could be determined.
 
R

RobG

David Mark said the following on 8/7/2007 9:52 PM: [...]
What is the createTextNode issue in IE? For script blocks?

Yes. If you createElement('script') and then use createTextNode to
create the text of the script element, all is fine. When you try to
appendChild the script element, IE barfs all over you.

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread...>

Is the very long winded thread on it.
I have to figure the workaround solution does not involve th UA
string.

No, it doesn't but something that is just as fragile and that is
conditional compilation.
Regardless, as you say, it would be preferable if a reliable
feature test could be determined.

I haven't given up on it yet. The problem is that all browsers (that I
know of) except one on a MAC supports simply setting the .text property.
It supports createTextNode with a script element but IE doesn't.

Is conditional compilation for IE more reliable than UA string
matching to detect Safari?
 
D

David Mark

David Mark said the following on 8/7/2007 9:52 PM:








Yes. If you createElement('script') and then use createTextNode to
create the text of the script element, all is fine. When you try to
appendChild the script element, IE barfs all over you.

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread...>

Is the very long winded thread on it.



No, it doesn't but something that is just as fragile and that is
conditional compilation.


I haven't given up on it yet. The problem is that all browsers (that I
know of) except one on a MAC supports simply setting the .text property.

I looked at the thread, but I assume it is outdated at this point.
What Mac browser fails and is reading back the text property an
indication of failure?
It supports createTextNode with a script element but IE doesn't.

Without seeing your latest logic, I can't follow the ramifications of
that statement. If you don't like conditional compilation or think it
is inappropriate for this problem, I suggest you wrap the appendChild
line in a try/catch block.
 
R

Richard Cornford

You need to filter out the others in this microverse who'll
tell you that you can't rely on the user agent.

That would be a stupid position to take. A more reasonable potion would
be to try to understand why these things are being said, by asking if
necessary.

The theory of trying to use a browser's User Agent header (or the
corresponding navigator.userAgent string) in order to identify the
browser, its version, and possibly the OS and its version, implies that
each and every browser provides a unique, consistent and immutable
sequence of characters in that header, that contain or imply all of the
necessary information. Then all you need to do is find out the UA header
of every browser that ever has and ever will exist and write a script
that examines them extracts the required information.

The reality of User Agent headers is that the HTTP 1.1 specification
requires no more than that the User Agent send such a header. There are
no technical requirements on the contents of that header; it is
effectively specified as being any arbitrary sequence of characters that
do not even have to be consistent over time. This is what makes it
technically bass-less to speak of browsers/users telling lies; no lies
can be told because there are no criteria for a 'correct' sequence of
characters in a User Agent header.

It is unusual for the User Agent headers used by web browsers not to be,
to some degree, designed to imitate the User Agent headers of other
browsers, and quite common for this to be carried to a point where a
browser's User Agent header is indistinguishable form the User Agent
header of another. For example, Web Browser 2, running on the Palm OS,
used the header "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)", from
which it is impossible to deduce the browser, its version or the OS
being used (and the results of the attempt, while certainly appearing to
be successful, will be actively misleading).

In many cases the user Agent header is user configurable, either
absolutely or by making s selection form alternatives, and the browsers
that offer no mechanism for modification tend to also be the ones that
deliberately set out to send User Agent headers that are
Indistinguishable from those of other browsers.
They don't live in the real world

The real world is the one where there is not formal requirement that
User Agent headers be any more than an arbitrary sequence of characters,
where real browsers deliberately send User Agent headers that are
indistinguishable from the User Agent headers of other browsers and the
users are capable of modifying (some of) those headers in anyway they
choose, and cannot be faulted for doing so because there are not doing
anything contrary to the formal requirements of HTTP.

Is the person living in the real world the person looking at strategies
for dealing with the reality of what a User Agent header is (by
specification and in reality, that is, not a source of information), or
someone working to a theory that these things are unique, consistent,
informative and discrimination, regardless of the evidence?
and have the luxury of telling their employers "NO" to
any request to produce code that would require looking
at the user agent string.

Is there such a thing as "code that would require looking at the user
agent string"? Or are there real problems where looking at the user
agent header might look to some like a solution, so long as they don't
perceive the reality of the situation, but to which there may be (and
hopefully will be) alternative applicable strategies?

After all, if the problem as stated is; 'I need to discriminate between
the sources of arbitrary sequences of characters by examining the
sequences of characters they produce' then the reasonable response to
the person making that specification is that achieving their requirement
is a logical impossibility. Going of an writing software would be
unprofessional, unsuccessful, and ultimately dishonest.
Those of us that have to live with reality know that
the user agent is the best info we've got

The User Agent header is not information at all, by specification. You
may not see yourself as having anything better, but that still does not
make it into information.
and does the job as well as we need it to.

We only need to do the job badly? Well, people certainly can get way
with doing the job badly (and very many do).
I've tried staying out of the threads they had about
it because they were just back and forth amongst themselves.

Mostly because the people taking the pro-browser sniffing position find
it nearly impossible to narrow down to the specifics of there real
problems, and so cannot be shown what may be possible.
When I see them force that diatribe on an unsuspecting noob
like yourself then I don't want to let them convince you
(with the two replies so far) that you can't do anything.

Who said nothing can be done? The specifics of the problem have not been
exposed, just one proposed solution. All that has been said that that
the proposed solution to the unnamed problem is a non-starter.
You can do something and it's better than nothing.

Don't you recognise the possibility that dong the wrong thing can easily
be worse than doing nothing?
I'm assuming you have a genuine need for it and can't do
feature detection.

Why assume that, without any specific information. After all, someone
asking about user Agent strings is clearly ignorant of pertinent aspects
of User Agent strings and attempting to apply a strategy that was
recognised as non-viable a decade or so ago. It makes no sense at all to
assume that such an individual has performed a complete and informed
analysis of their problem.

Richard.
 
T

Thomas 'PointedEars' Lahn

Gregor said:
Johannes Schmidt meinte:

[utter crap]

But what can you expect from somebody of the Jerusalem School of
Synoptic Research who ventures into the realm of client side scripting...

Ah, I had not watched for meaning of the From header :)

Please do not feed the troll.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Richard said:
The reality of User Agent headers is that the HTTP 1.1 specification
requires no more than that the User Agent send such a header.

Not even that. "SHOULD" specifies a strong recommendation, not a
requirement (that would be "MUST"). See RFC2616, 14.43, and RFC2119.


PointedEars
 
W

william.oram

Is there a way to use JavaScript to distinguish between Mac OS X 10.4
and earlier OS X versions like with Windows? browserType.UserAgent
outputs the following on a 10.4 machine, which (to me) says nothing
about the specific OS:

mozilla/5.0 (macintosh; u; ppc mac os x mach-o; en-us; rv:1.8.1.3)
gecko/20070321 firefox/2.0.0.3

Thanks,
Will

It appears this question has stirred a lot of grumpiness up. I wish I
had encountered the FAQ before coming here, even though it wouldn't
have answered my particular question.

To the people who seem to be in disbelief that browser detection is
absolutely necessary for me...well, believe what you will. The project
I am part of isn't intended for mobile devices or computers with three
inch screens; the user base is likely sitting at a desk. I maintain a
web components check page, and one of the prerequisites as established
is a Firefox, IE or Safari 2 (Safari 1.2 if 10.3) browser. I don't
think it's fair to suggest I'm turning in ineffective, garbage code by
allowing browser check code to exist (which already did exist when I
arrived!). If a user is willing to lie, cheat and steal to circumvent
the browser check, he risks losing the benefits of the website if
there is a layout quirk, and that is HIS fault. (The fact the user has
shelled out money should be enough to convince him to adhere to system
reqs, no?)
 
D

David Mark

It appears this question has stirred a lot of grumpiness up. I wish I

Not at all. But it did attract the attention of a troll.
had encountered the FAQ before coming here, even though it wouldn't
have answered my particular question.

Actually, it would have.
To the people who seem to be in disbelief that browser detection is
absolutely necessary for me...well, believe what you will. The project

You should believe it too as it is true.
I am part of isn't intended for mobile devices or computers with three
inch screens; the user base is likely sitting at a desk. I maintain a

That has nothing to do with it.
web components check page, and one of the prerequisites as established
is a Firefox, IE or Safari 2 (Safari 1.2 if 10.3) browser. I don't

So put a form on that page for the user to pick which they are using.
Do you have any idea how many non-IE agents identify themselves as IE?
think it's fair to suggest I'm turning in ineffective, garbage code by

But you clearly are.
allowing browser check code to exist (which already did exist when I

So delete it.
arrived!). If a user is willing to lie, cheat and steal to circumvent

The agents lie. Their developers tell them to. The users are often
completely unaware. However, you don't have to rely on lying agents
when you can ask the user what they are using.
the browser check, he risks losing the benefits of the website if
there is a layout quirk, and that is HIS fault. (The fact the user has

So because you don't understand how browsers work or why they work
that way, you will write a failure-prone "web components check page"
and blame the users for any problems.
shelled out money should be enough to convince him to adhere to system
reqs, no?)

And this is supposed to be a pay site? You are going to turn away
business to prevent layout quirks?!

Good luck.
 
D

David Mark

David Mark said the following on 8/8/2007 8:18 PM:



I know of one that mimicks IE in the UA string perfectly but it is *far*
from being IE.

Certain versions of NetFront I think. ICEBrowser for another.

On the flip side, there are likely hundreds of agents out there
compatible with this site that don't identify as IE, FireFox or Safari
and therefore would be turned away at the gate. In other words, "we
don't want your money as your UA string isn't on the list."
 
D

David Mark

David Mark said the following on 8/8/2007 8:47 PM:







And that abomination I lovingly refer to as my cell phone :)

I thought that was NetFront? My cell phone (Motorola v600) works
pretty well with the page I am currently testing. I have noticed that
it downloads and combines alternative style sheets. Even worse, for
some ridiculous reason one static link that references a static anchor
on the same page is failing (it does nothing.) It is an important
link too, so I am going to have to find out what is so special about
it. Bookmark links to other pages work fine so it clearly understands
anchors.
Most people discount that "money" aspect and claim that it isn't a lot
of money and isn't worth the effort. Sometimes it isn't and sometimes it

Of course, half of Europe is off of IE at this point and they love
spoofing over there.
is. When it is, it behooves you to try to cover as much as possible or
it can bite you badly.

The first time I ever ran into it, it was with NN4 sometime in 2002 or
so and was worth 100,000 USD a month. The last time? Not two months ago
and it was worth a 2 million dollar inventory order. The reason the
order couldn't be place? They couldn't identify the browser making the
request based on a userAgent string. The browser in question? IE7 behind
proxies. The UA String that the server was getting was the proxies UA
string. It didn't "match IE" so it kept rejecting it telling us to
"Update your browser". The vendor's marketing department didn't like me
after I explained what inept idiots they had programming for them and it
was miraculous how fast they stopped UA detection.

Server side sniffing? Serves them right.

I hate marketing departments. They all seem to follow the same rules:

1. Fixed width layout.
2. Pixel perfect layout that is only feasible with tables-in-tables-
with-spacers.
3. Fixed, microscopic font sizes (and Verdana is their favorite.)

Throw in lots of Flash (or Prototype), huge images, etc. and that is
their basic handbook. It's the idiot's guide to Web development.

And they think that if it looks good in the latest IE, then there is
no reason to listen to objections from technical people. Everybody
uses IE right?
So don't think it can't be a large sum of money that is going to bite
you in the ass.

I can understand that salesmen don't get the technical aspects of it,
but they should understand the concept of losing out on sales. I've
heard marketing people say things like "We don't get any complaints
through our feedback form." As if a disgruntled user who goes to the
site down the block is going to take the time to report problems
(assuming the feedback form is remotely accessible in the first
place.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top