There's nothing like going to the source and seeing: :-)


But generally, Prototype is moving / has moved away from browser
sniffing as much as possible, toward feature detection. This has been
going on for a while, and I *think* one could safely say that 1.6.1
mostly uses feature detection even though there are a couple of
browser sniffs left. (Somebody jump in to correct me if they've all
been dealt with.)

Feature detection rather than browser sniffing is more reliable and
more robust. So for example: When using `setAttribute`, some browsers
expect that you'll call the `class` attribute "class":

    element.setAttribute("class", "foo");

others expect you'll call it "className":

    element.setAttribute("className", "foo");

Prototype, like other libraries, works around this for you if you use
its `setAttribute` replacement `writeAttribute`. Now, a naive library
might try to smooth that out by using browser sniffing and its built-
in knowledge that IE uses "className", Firefox and Chrome use "class",
etc. But this is fragile, if the library sees a browser it doesn't
"know" it has to guess; you have to get into browser versions because
things can change (the IE team might decide to support "class"), and
you end up with big branching constructs that are difficult to

Feature detection handles this in a very straightforward way: Go find

    var div = document.createElement('div');
    try { div.setAttribute("class", "foo"); } catch (e) { }
    if (div.className == "foo") { // Note we're using the property
        /* ...this browser calls it "class"... */

And so on for the "className" test (and "for" vs. "htmlFor", etc.).
Having tested it once, Prototype remembers which one this particular
browser uses, and uses it when you use `writeAttribute`. Feature
detection future-proofs the library, and (perhaps surprisingly)
simplifies it a bit as well.

Kangax (a contributor to Prototype and other libraries) has a library
of common feature tests:

T.J. Crowder
Independent Software Consultant
tj / crowder software / com

On Mar 22, 8:15 am, gipper2006 <gipper2...@gmail.com> wrote:
> Hellow! Can anybody say how does detect brouser type in prototype?

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to