User Agent Detection Logic

  • Thread starter Lasse Reichstein Nielsen
  • Start date
L

Lasse Reichstein Nielsen

But, if browser detection is the way to go, as you claim, could you _please_
show me how to do this simpler? Using Browser Detection:

if (document.images){
//lets work with images
}

I would say "let's work with document.images". I often see people writing
if (document.images) {
var img1 = new Image();
img1.src = "foo.png";
...
}

Statistically, it appears that there is a strong correlation between
document.images and window.Image (both introduced in Netscape 3 and
both exists in all later browsers), but it is not object detection.

/L
 
F

Fotios

Hey Randy, does you momma know you still up?
His last post being the one to me that convinced me he was under the false
impression he possesses some intelligence.

Randy, tell us (please?) what is wrong with this: "...being the one to me
that convinced me...".
You don't even listen to your teacher you naughty boy you.
My hats off to you Richard, you have argued your point (successfully) with the
moron way longer than I ever would have.

Hey Randy, how many hats do you wear at once? Itz kewl. I did it too (when I
was 14)

F.
 
L

Lasse Reichstein Nielsen

Its not browser detection either though.

No, it is ... "object inferenece"? It is similar to testing for
document.all and assuming the browser works like IE, only with a much
higher positive rate :)
But another example can be:

if (document.getElementById){
//lets use document.getElementById
}

Yes, that is a good one. Your example could very well be one too, if
you only used document.images in the body of the test. I was just
griping about having seen a lot of "if (document.images) {new Image...}"
recently.
Not wanting to get into the testing argument again, but neither of these is
browser detection, nor do I need to know the browser. Its irrelevant, no?

Absolutely. I advocate object detection too, but all object detection will
eventually assume something about the detected objects. Finding a property
called "getElementById", or even a function by that name, doesn't tell us
what it does. We have to assume that the browser manufacturer isn't being
stupid or deliberatly malicious. But I prefer trusting the behavior of a
feature to trusting its existence.

/L
 
K

kaeli

But, if browser detection is the way to go, as you claim, could you _please_
show me how to do this simpler? Using Browser Detection:

if (document.images){
//lets work with images
}

Your move stupid.

Haven't you yet learned the futility of trying to have a debate with the
mentally challenged? :p
Don't have a battle of wits with an unarmed opponent. It isn't nice.

Or are you just playing with him because you're bored? *LOL*

-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
F

Fotios

Haven't you yet learned the futility of trying to have a debate with the
mentally challenged? :p
Don't have a battle of wits with an unarmed opponent. It isn't nice.

Or are you just playing with him because you're bored? *LOL*

heehee! Kaeli, you are such a cutie! *LOL* ooooxxxx

New agey love,
F.
 
F

Fotios

Richard,

I have read your lengthy reply. Many thanks.

I don't believe that continuing this thread has anything more to offer to
the group or us.

It is obvious we disagree but I sure can live with that.

My views on the subject have basically been expressed to a good extend in my
last two lengthy posts.

I want to believe that everybody's (whether reader or poster) grasp of the
involved issues has been either improved or refreshed.

At the very least, we got the fairly new idea of deceiving objects to show
for.
Who knows? Maybe Fudgilla will become a reality at some point just to show
that there are no certainties except temporary ones.
I promise you; it will not be me who puts it together :)

Best regards,
Fotios
--
http://fotios.cc/

Richard Cornford said:
Judging by your posts to microsoft.public.scripting.jscript under this
subject you are not a good Christian so perhaps you should RTFM.

....
<snip>
 
R

Richard Cornford

HikksNotAtHome said:
His last post being the one to me that convinced me he was under
the false impression he possesses some intelligence.

Yes, that is exactly the post that I had in mind. Resorting to
unsubstantiated sarcastic abuse did not strike me as consistent with the
teachings of Christ as reported in the Bible (not that I have any
expertise, being an atheist, but I am not unfamiliar with scripture),
nor as the resort of someone who believes they have a valid rational for
their position.
My hats off to you Richard, you have argued your point
(successfully) with the moron way longer than I ever would have.

Well, it is not as if it was ever possible to fail when arguing against
userAgent string based browser detection (as Steve pointed out a couple
of days ago). Not that I was expecting to convince him. To be convinced
by reasoned argument you have to be rational (and possibly intelligent)
to start with (and the ability to accurately comprehend written English
would also have been useful in this context).

My main motivation is to provide a service to those who may in future,
believing that they need to detect browsers, search c.l.j. on google and
find their keywords directing them to this thread. I would not want them
to go away the impression that browser detecting by userAgent string was
a good idea, possible, acceptable ,actually necessary or in any way
endorsed by this group, and to give some alternative keywords to search
on. There is no need to let people who are new to the subject repeat the
mistakes of the past.

I suspect you had a similar intention when responding to him on
microsoft.public.scripting.jscript.

Richard.
 
R

Richard Cornford

I don't believe that continuing this thread has anything more
to offer to the group or us.

So a thread in which you have challenged people to reply to your points
at least twice comes to an end when you find yourself unable to respond
to mine. That suites me, and I would agree that the subject has been
satisfactorily addressed.

My views on the subject have basically been expressed to a good
extend in my last two lengthy posts.

Yes they have, and my last two lengthy posts have addressed them all.
I want to believe that everybody's (whether reader or poster)
grasp of the involved issues has been either improved or refreshed.

Maybe some readers, I don't think that any of the other posters in this
thread have seen anything that they were not already familiar with.
At the very least, we got the fairly new idea of deceiving
objects to show for.

Fairly new idea? That concept was in the FAQ when you supposedly read it
two years ago. c.l.j. has been discussing and refining the techniques of
feature/object detecting on a regular basis for as long as I have been
reading it. That is why we are all so confident that it is the _only_
viably approach to Internet browser scripting. (Though individual
opinions on how the technique is best applied still varies, but that is
what would be expected when individuals address complex problems.)
Who knows? Maybe Fudgilla will become a reality at some point
just to show that there are no certainties except temporary ones.
I promise you; it will not be me who puts it together :)

And I promise you that if you don't write it nobody else is going to.
What could possibly motivate anyone else to put their effort into
writing a browser with a deliberately broken DOM? That is the sort of
thing that people only do by accident. If they wanted a browser that
predictably would not execute any existing JavaScript they could just
strip scripting support from the browser entirely, and if they wanted a
browser that would only execute their own scripts it would be easier to
swap the scripting language from JavaScript to some other.

Richard.
 
F

Fotios

Richard,

I will not deal with the rest of the stuff that you mention (to which I
disagree) or the fact that you seem to have somehow gotten emotionally
involved (sorry if I caused this).

I will not even try to get into a theological discussion with you (which I
don't see how it is not OT - you being so sensitive about OT stuff).

I will even hold my ironic remarks to your admission that you are an atheist
(I don't want you to have a stroke or anything).

However, I will respond to the following just to demonstrate to you how
intensive FAQ reading and adherence (and other dogmatisms) can impair
imagination.
And I promise you that if you don't write it nobody else is going to.
What could possibly motivate anyone else to put their effort into
writing a browser with a deliberately broken DOM? That is the sort of
thing that people only do by accident.

Imagine this dear Richard: Let's say I am an open source proponent who is
sick and tired of Microsoft's marketing tricks and the way they undermine
public standards. So, I build this excellent open source browser which
supports all W3C DOM objects (in a very proper way) but I also choose to
attack Microsoft in my own way by faking the proprietary Microsoft objects
or methods/properties; that is they exist but they give erroneous values
(like: "Billy is a custard face" instead of some other string that is
expected). Why would I do that? But because this way I would break scripts
that try to support these objects. This would be an angry open sourcer's way
of fighting back and saying out loud "Scripters! Do not script for
Microsoft's proprietary objects/methods/properties that antagonize and
undermine W3C standards". Extreme in a way but I think conceivable - in my
opinion, not more extreme that having Shakespeare quotes as your agent
string.

F.
 
J

Jim Ley

I also choose to
attack Microsoft in my own way by faking the proprietary Microsoft objects
or methods/properties; that is they exist but they give erroneous values
(like: "Billy is a custard face" instead of some other string that is
expected).

Well the script will almost certainly reject your browser when it
checks for the document object, which doesn't exist in the W3 DOM.

However the object detection technique, will have no problem with
this, consider document.all.chicken returning your string instead of
an object, that will fail when you check the chicken object is what
you expect, or that the chicken.style is indeed an object, your
intentional spoofing only works if you don't spoof objects, but make
them do intentionally wrong things (e.g. have a style visibility
change the colour instead or something) So you'd have to deliberately
break the objects behaviour not just have them return a string.

However, all of it's academic, as you've implemented the W3 DOM, and
clj has always advocated checking and using that first, so our scripts
won't see your mess, just old ones...
Do not script for
Microsoft's proprietary objects/methods/properties that antagonize and
undermine W3C standards".

Except of course that doesn't work, because the W3 simply hasn't
standardised huge gaping holes which are requied to do any scripting,
de facto standards are required.

Jim.
 
R

Richard Cornford

Fotios said:
I will not deal with the rest of the stuff that you mention
(to which I disagree) or the fact that you seem to have
somehow gotten emotionally involved (sorry if I caused this).

Given your demonstrated shortcomings in extracting literal meaning from
written English I think you would be best advised to concentrate on that
and abandon efforts to interpret emotional overtones until you have that
under your belt. As I recall my emotional response to your last post was
nothing more than slight amusment (at the fact that Steve's predicted
outcome had come to pass).
I will not even try to get into a theological discussion
with you (which I don't see how it is not OT - you being
so sensitive about OT stuff).

It would be OT, but should you consider yourself properly equipped for a
theological discussion if you have not read the Bible?
I will even hold my ironic remarks to your admission that you
are an atheist (I don't want you to have a stroke or anything).

I see no irony (or anything unusual) in an atheist being able to
recognise hypocrisy.

Imagine this dear Richard: Let's say I am an open source
proponent who is sick and tired of Microsoft's marketing
tricks and the way they undermine public standards. So,
I build this excellent open source browser which supports
all W3C DOM objects (in a very proper way) but I also
choose to attack Microsoft in my own way by faking the
proprietary Microsoft objects or methods/properties; that
is they exist but they give erroneous values (like: "Billy
is a custard face" instead of some other string that is
expected). Why would I do that? But because this way I
would break scripts that try to support these objects.
This would be an angry open sourcer's way of fighting
back and saying out loud "Scripters! Do not script for
Microsoft's proprietary objects/methods/properties that
antagonize and undermine W3C standards". Extreme in a way
but I think conceivable - in my opinion, not more extreme
that having Shakespeare quotes as your agent string.

Mozilla already says "Scripters! Do not script for Microsoft's
proprietary DOM" by the simple measure of not implementing very much of
it (though you might break innerHTML just to be comprehensive).

The browser you are describing is not significantly different from the
W3C DOM compliant browsers that fake objects from the Microsoft DOM in
order to avoid being ostracised by scripts that attempt browser
detection by object inference. And feature detecting as a technique
already copes quite happily with those browsers. To the best of my
recollection, as you describe it this browser is going to happily
execute _every_ feature detecting script I have ever written because I
have always favoured using W3C DOM methods over proprietary ones, only
falling back to a proprietary methods if a W3C DOM approach is not
available/functional on the browser.

To significantly impact on the effectiveness of feature detecting as a
technique you would have to pervert the _entire_ browser DOM well beyond
the point at which no existing browser detecting based script could work
on it either. And even then the chances are still good that a feature
detecting script would recognise its inability to execute and be in a
position to degrade cleanly under control, while the browser detection
based scripts (assuming that they were allowed the opportunity to run on
this unrecognised browser) would just error until they failed entirely.

The result would be a browser that could _only_ execute scripts that
were specifically written for its perverse DOM. If making scripting the
browser require specialist knowledge was the goal of the browser authors
then it would be easiest achieved by just switching to a non-standard
scripting language, and if the goal was a browser that would not
successfully execute anyone's scripts then that would be easiest
achieved by just stripping scripting out entirely.

That leaves you as the only person motivated to go down the totally
perverse DOM route. And yes it may demonstrate that feature detecting
scripts cannot cope 100% with anything at all. On the way you have also
killed off all browser detecting scripts, so all that such a browser
would server to demonstrate is that while feature detecting cannot be
100% it is still significantly more robust than browser detecting. I
don't see that as contributing in any way towards an argument in favour
of browser detecting, quite the reverse.

Richard.
 
R

Richard Cornford

I note the use of the phrase: "actually necessary." Is
there some concensus, even among a few, that browser
detection, of any kind, is not necessary or desirable?

There is complete consensus that browser detecting based on the
navigator.userAgent string cannot uniquely identify individual web
browsers, that is just a truth. There may be approaches based on object
inference that can uniquely identify some (but not all) browsers, but it
would be necessary to have complete details of _all_ browser DOMs in
order to have any confidence in the results, and that is impractical.
The individuals with the widest familiarity with browser DOMs freely
admit that even they do not know enough to implement a truly
discriminating object inference based browser detecting script. And even
if it was done such a script would need to be updated whenever a new
browser was released (world wide).

So if there are circumstances under which it is *necessary* to uniquely
identify a web browsers then the impossibility of doing that becomes an
insurmountable problem.

People do occasionally propose circumstances under which they believe
that they need to identify browsers but these usually turn out to arise
due to a lack of understanding of HTML or CSS and when they are genially
JavaScript problems there is often either an alternative approach that
circumvents the problem or and examination of the logic of the problem
indicates a specific test that will discriminate browsers that have the
problem from those that don't without the need to know which browsers
those are. And, of course, there are a few things that just cannot be
done (or tested) with sufficient reliability to be appropriately used
outside of an Intranet.

There is a very wide consensus (at least among those knowledgeable about
browser scripting) that testing the features specifically required by a
particular script is the only viable technique for cross-browser
scripting, thus side-stepping the fact that browsers cannot be uniquely
identified by never asking that question.

You can judge the support for browser detection by the total number of
people contributing to this thread in support of that approach.
I am new to JavaScript and am just curious. At this
point I have doing HTML strict 4.01 on Opera 7.11, with
no concern for cross-browser compatibility.

Client-side Internet JavaScript is probably unique in computer
programming terms in that it has to be authored with zero certainty
about the environment in which it will be executing. To be effective its
authors have to embrace that fact and adopt a different attitude towards
achieving their goals. But without that challenge cross-browser
scripting would be no more interesting than working with many other
programming languages. I would always recommend aspiring to author
cross-browsers scripts. After all a cross-browser scripter can author
for any specific browsers, the reverse is not true.

Richard.
 
L

Lasse Reichstein Nielsen

Fotios said:
Anyone who can think straight can see how a browser like the one I have
described would make the detection style you are a proponent of a big
problem in many cases.

A browser that implements W3C DOM perfectly[1], but which maliciously
distorts proprietary IE features, will work perfectly with object
detection ... because you should always test for W3C DOM first.

/L
[1] Including widely accepted non-W3C objects that are not originated
at Microsoft, e.g., the global "document" and "window" variables.
 
J

Jim Ley

A browser that implements W3C DOM perfectly[1], but which maliciously
distorts proprietary IE features, will work perfectly with object
detection ... because you should always test for W3C DOM first.

Have you noticed how you are suddenly on a "should" basis?

Well you're the perfect example of how people don't understand object
detection... what other word than SHOULD do you think Lasse should be
using? it can't be MUST, we have no control over people, so what
exactly do you suggest?

Jim.
 
J

Jim Ley

No, it should be SHOULD which is exactly my point. To make it more explicit
for you, gone is the certainty that object and property checking just works.

Of course it does work if it's written correctly, however your user
agent sniffing cannot be written correctly in such manner that works
with even known browsers, you're relying on some very weird
hypothetical browser that does not exist - making it with IE would be
pretty easy.
BTW, the first Fudgilla Service Pack was released. Fudgilla will now check
for instances of proprietary Microsoft objects/properties anywhere in the
script and if it finds even one it will mess up the script anyway.

So it will "mess up the script" across the proprietary Microsoft
object like "document" then? and pray tell me how this is done, the
code analysis methods would be really useful to me for other things,
any language is good.

Jim.
 
R

Richard Cornford

"code analysis methods" when all that would be needed is
simple substring detection?

And now a browser that supposedly was created to promote web standards
is in breach of ECMA 262.

Richard.
 
J

Jim Ley

"code analysis methods" when all that would be needed is simple substring
detection?

no, that doesn't work...

all='getElementById'
document[all]()

or even just

document.fred

that uses IE proprietary, yet ain't gonna be found by simple substring
detection.

Jim.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top