Browser Check

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • McKirahan

    Browser Check

    Is this a very good browser check?

    <html>
    <head>
    <title>wB.htm </title>
    <script type="text/javascript">
    var adBtype = "??";
    function wB() {
    if (document.getEl ementById && !document.all) {
    adBtype = "NS6+";
    } else if (document.getEl ementById && document.all) {
    adBtype = "IE5+";
    } else if (document.all) {
    adBtype = "IE4";
    } else if (document.layer s) {
    adBtype = "NS4";
    }
    alert(adBtype);
    }
    </script>
    </head>
    <body onload="wB()">
    <body>
    </html>

    Opera 6.01 returns "IE5+"; don't know about others...


  • Andrew Urquhart

    #2
    Re: Browser Check

    "McKirahan" <News@McKirahan .com> wrote in message
    news:Jm9%b.5668 6$Xp.269424@att bi_s54...[color=blue]
    > Is this a very good browser check?[/color]

    <script cut>

    See: http://jibbering.com/faq/#FAQ4_26
    --
    Andrew Urquhart
    - FAQ: http://jibbering.com/faq
    - Archive: http://groups.google.com/groups?grou...ang.javascript
    - Reply: https://www.andrewu.co.uk/about/cont...=newsgroup_clj


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Browser Check

      "McKirahan" <News@McKirahan .com> writes:
      [color=blue]
      > Is this a very good browser check?[/color]

      No. I can say that without reading, because browser checks are almost
      invariably not good, no matter how efficient they are :).

      (Remember DOCTYPE, it is required by HTML)
      [color=blue]
      > var adBtype = "??";
      > function wB() {
      > if (document.getEl ementById && !document.all) {
      > adBtype = "NS6+";[/color]

      Or Opera 6 or ....
      [color=blue]
      > } else if (document.getEl ementById && document.all) {
      > adBtype = "IE5+";[/color]

      Or Opera 6 (in IE mode) or Opera 7 or ...
      [color=blue]
      > } else if (document.all) {
      > adBtype = "IE4";[/color]

      Or WebTV or ....
      [color=blue]
      > } else if (document.layer s) {
      > adBtype = "NS4";[/color]

      Or OmniWeb or ...
      [color=blue]
      > Opera 6.01 returns "IE5+"; don't know about others...[/color]

      Not knowing about others is *the* problem with browser detection.
      Optimistically it is hard work to become familiar with all browsers,
      realistically, it is quite impossible. You will invariably miss some
      browsers that are in actual use, and will most likely badly
      misrepresent future browsers.

      The way to make scripts usefull across as many browsers as possible
      are:
      1) Use standards! It gives you the best chance of forward compatability.
      2) Use object/feature detection, not browser detection, to make fallbacks
      for non-standard-compliant browsers.

      Object detection coulde be:

      var elem;
      if (document.getEl ementById) {
      elem = document.getEle mentById(id);
      } else if (document.all) {
      elem = document.all[id];
      } else if (document.layer s) {
      elem = document.layers[id];
      } else {
      elem = null;
      }

      Before using a standard feature that some browsers are known to be
      incompatible with, you test for its existence. If it doesn't exist,
      you test for the existence of some other feature that might (or might
      not) be used instead. Notice that the above code doesn't care whether
      it is IE 5+ or NS 6+ or whatever. It is not perfect code! There are
      cases where it fails too, which further testing could fix. And some
      that it can't (some browsers are just broken, or doesn't have
      Javascript enabled).

      It is important to realize that old browsers that nobody uses will not
      become more used in the future, but future browsers will. That makes
      forward compatability more important than backwards compatability.
      Detecting specific versions of known browsers will necessarily not
      work for future versions.


      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Mick White

        #4
        Re: Browser Check

        McKirahan wrote:

        [color=blue]
        > <script type="text/javascript">
        > var adBtype = "??";
        > function wB() {
        > if (document.getEl ementById && !document.all) {
        > adBtype = "NS6+";
        > } else if (document.getEl ementById && document.all) {
        > adBtype = "IE5+";
        > } else if (document.all) {
        > adBtype = "IE4";
        > } else if (document.layer s) {
        > adBtype = "NS4";
        > }
        > alert(adBtype);
        > }
        ></script>[/color]

        There's no escape for the function:


        function wB() {
        if (document.getEl ementById && !document.all) {
        adBtype = "NS6+";retu rn;
        }
        if (document.getEl ementById && document.all) {
        adBtype = "IE5+";retu rn;
        }
        if (document.all) {
        adBtype = "IE4";retur n;
        }
        if (document.layer s) {
        adBtype = "NS4";retur n;
        }
        adBtype= "unknown to this programmer";
        }
        Mick

        Comment

        • McKirahan

          #5
          Re: Browser Check

          "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
          news:0Fb%b.9200 8$%72.76902@twi ster.nyroc.rr.c om...[color=blue]
          > McKirahan wrote:
          >
          >[color=green]
          > > <script type="text/javascript">
          > > var adBtype = "??";
          > > function wB() {
          > > if (document.getEl ementById && !document.all) {
          > > adBtype = "NS6+";
          > > } else if (document.getEl ementById && document.all) {
          > > adBtype = "IE5+";
          > > } else if (document.all) {
          > > adBtype = "IE4";
          > > } else if (document.layer s) {
          > > adBtype = "NS4";
          > > }
          > > alert(adBtype);
          > > }
          > ></script>[/color]
          >
          > There's no escape for the function:
          >
          >
          > function wB() {
          > if (document.getEl ementById && !document.all) {
          > adBtype = "NS6+";retu rn;
          > }
          > if (document.getEl ementById && document.all) {
          > adBtype = "IE5+";retu rn;
          > }
          > if (document.all) {
          > adBtype = "IE4";retur n;
          > }
          > if (document.layer s) {
          > adBtype = "NS4";retur n;
          > }
          > adBtype= "unknown to this programmer";
          > }
          > Mick[/color]

          Actually I modified one I found; it actually was:

          function wB() {
          if (document.getEl ementById && !document.all) {
          adBtype = "NS6+";
          return;
          } else if (document.getEl ementById && document.all) {
          adBtype = "IE5+";
          return;
          } else if (document.all) {
          adBtype = "IE4";
          return;
          } else if (document.layer s) {
          adBtype = "NS4";
          return;
          }
          }


          Comment

          • kaeli

            #6
            Re: Browser Check

            In article <Jm9%b.56686$Xp .269424@attbi_s 54>, News@McKirahan. com
            enlightened us with...[color=blue]
            > Is this a very good browser check?[/color]

            No, but it's a great way of doing object detection. :)

            There is NO good browser check. There are simply too many browsers.

            --
            --
            ~kaeli~
            I do whatever my Rice Krispies tell me to.



            Comment

            • Mick White

              #7
              Re: Browser Check

              McKirahan wrote:

              [color=blue]
              >
              > Actually I modified one I found; it actually was:
              >
              > function wB() {
              > if (document.getEl ementById && !document.all) {
              > adBtype = "NS6+";
              > return;
              > } else if (document.getEl ementById && document.all) {
              > adBtype = "IE5+";
              > return;
              > } else if (document.all) {
              > adBtype = "IE4";
              > return;
              > } else if (document.layer s) {
              > adBtype = "NS4";
              > return;
              > }
              > }
              >[/color]

              What if all the Booleans are false? You need to declare a global variable:
              var adBtype="Unknow n" // A suggestion.
              But read the other comments, there are probably hundreds of different
              browsers out there, some of which obfuscate their headers. IOW your
              "adBtype" is just a guess.
              Mick

              Comment

              Working...