<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="/lib/xsl/devedge-1.00/article_en.xsl"?>
<nde:article 
  url="/toolbox/examples/2002/xb/ua/" 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:nde="http://devedge.netscape.com/2002/de"
  xmlns:ent="http://devedge.netscape.com/2003/ent"
  xml:lang="en"
  >

 <nde:header>

   <nde:title>
     Script ua.js
   </nde:title>

   <nde:category>
     Manpage
   </nde:category>

  <nde:pubdate year="2002" month="04" day="21" />
  <nde:moddate year="2002" month="07" day="22" />

  <nde:summary>
      Practical Browser Sniffing Script
  </nde:summary>

  <nde:authlist>
    <nde:author>
      <nde:authname>Bob Clary</nde:authname>
      <nde:authaffil>Netscape Communications</nde:authaffil>
    </nde:author>
  </nde:authlist>

  <!--
  <nde:obsolete url="/viewsource/2002/browser-detection/">
    Browser Detection and Cross Browser Support for the 
    recommended approach to browser detection
  </nde:obsolete>
  -->

  <nde:channels>
    <nde:channel id="examples"/>
    <nde:channel id="xb-2002"/>
  </nde:channels>

  <nde:keywords>solutionfinder, browser detection</nde:keywords>

</nde:header>


 <nde:head>
 </nde:head>

 <nde:content>
   <h2>Synopis</h2>
   <pre><![CDATA[void xbDetectBrowser();]]></pre>

    <h2>Source</h2>
    <p>
      <a href="ua.js">ua.js</a>
    </p>

    <h2>Uses</h2>
    <ul>
      <li>nothing</li>
    </ul>

    <h2>Description</h2>

    <p>
      xbDetectBrowser() is called when the script ua.js is loaded. It sets
      several properties on the window.navigator object which detail the 
      kind of browser being used as based upon the reported navigator.userAgent
      string.
      </p>
      <p>
        Please note that Object based sniffing is preferrable in most cases 
        to using detection based upon the navigator.userAgent string. Many
        browsers, Gecko and Opera for example, can be configured to report
        any User Agent String. Opera even changes the DOM they support depending
        upon whether the user has set their User Agent string to an IE compatible
        setting.  In addition, Object based sniffing will support any Browser which
        supports the approprioate objects while User Agent string based sniffing
        will only detect specific browsers.
      </p>

      <p>
        However, there are situations, for example when you need to distinguish
        between versions of the same browser, where User Agent string based sniffing is 
        appropriate.
      </p>

      <p>
        Please see <a href="/toolbox/examples/2002/xb/xbDOM/">xbDOM</a> for an example
        of Object based sniffing.
      </p>

    <h2>Example</h2>
      <h3>Download</h3>
      <p>
        <a href="examples/ua-examples.zip">ua-examples.zip</a>
      </p>

    <h2>
        <a href="examples/">Basic Example</a>
    </h2>

    <pre><![CDATA[<HTML>
  <HEAD>
    <TITLE>Browser Sniffing Example</TITLE>
    <SCRIPT LANGUAGE="JavaScript" SRC="ua.js"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
      document.write("<h1>Browser Sniffing Example</h1>");
      document.write("<ul>");
      document.write("<li>navigator.OS=" + navigator.OS + "<\/li>");
      document.write("<li>navigator.version=" + navigator.version + "<\/li>");
      document.write("<li>navigator.org=" + navigator.org + "<\/li>");
      document.write("<li>navigator.family=" + navigator.family + "<\/li>");
      document.write("<\/ul>");
      //-->
    </SCRIPT>
  </HEAD>
  <BODY>
  </BODY>
</HTML>]]></pre>

    <h2>properties set by ua.js</h2>
    <dl>
        <dt>navigator.OS</dt>
        <dd>
          <ul>
            <li>
              <p> &quot;win&quot; for all Windows platforms </p>
            </li>
            <li>
              <p> &quot;mac&quot; for all Macintosh platforms </p>
            </li>
            <li>
              <p> &quot;nix&quot; for all Unix like platforms </p>
            </li>
            <li>
              <p> &quot;&quot; if platform is not one of the above </p>
            </li>
          </ul>
      </dd>
        <dt>navigator.org</dt>
        <dd>
          <ul>
            <li>
              <p> &quot;opera&quot; for Opera based browsers </p>
            </li>
            <li>
              <p> &quot;netscape&quot; for Netscape browsers </p>
            </li>
            <li>
              <p> &quot;microsoft&quot; for Microsoft browsers </p>
            </li>
            <li>
              <p> &quot;compuserve&quot; for Compuserve browsers </p>
            </li>
            <li>
              <p> &quot;sun&quot; for HotJava </p>
            </li>
            <li>
              <p> &quot;&quot; if organization is not one of the above </p>
            </li>
          </ul>
      </dd>
        <dt>navigator.version</dt>
        <dd>
          <p>
            If the browser organization is one of the above, then the version will be reported in 
            navigator.version as a floating point number. Otherwise, the version will be 0.
            Note that Gecko based browser will report the Release Version from 
            the UserAgent string and not actual version reported by the vendor.
          </p>
      </dd>
        <dt>navigator.family</dt>
        <dd>
          <p>
            navigator.family contains a string that groups browsers into families that can
            be reasonably treated in a similar fashion. Different versions of a browser within
            a family can be distinguished by the navigator.version property.
            Current families that are detected are:
          </p>
          <ul>
            <li>
              <p> &quot;hotjava&quot; HotJava browsers from Sun </p>
            </li>
            <li>
              <p> &quot;opera&quot; Opera Browsers </p>
            </li>
            <li>
              <p> &quot;ie3&quot; Internet Explorer versions before 4 </p>
            </li>
            <li>
              <p> &quot;ie4&quot; Internet Explorer versions 4 and later </p>
            </li>
            <li>
              <p> &quot;gecko&quot; browsers based upon the Mozilla Open Source browser such as Netscape 6 </p>
            </li>
            <li>
              <p> &quot;nn3&quot; Netscape Navigator 3.x browsers </p>
            </li>
            <li>
              <p> &quot;nn4&quot; Netscape Navigator 4.x browsers </p>
            </li>
            <li>
              <p> &quot;aol&quot; AOL browsers </p>
            </li>
          </ul>
      </dd>
    </dl>
 </nde:content>

<nde:related area="nde">
  <nde:item url="/toolbox/examples/2002/xb/">More xbAPI Examples</nde:item>
  <nde:item url="/viewsource/2002/browser-detection/">Browser Detection and Cross Browser Support</nde:item>
</nde:related>

</nde:article>
