Monday, February 6, 2012

how to sniff browser specifications with jQuery

My last blog posting is terrible. Use this instead:

<div id="badbrowserspecifications"></div>

<script src="/Scripts/jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">

   var ua = $.browser;

   var txt = "<p>The browser you are using: ";

   if (ua.mozilla) {

      txt += "Firefox";

   } else {

      if (ua.msie) {

         txt += "Internet Explorer";

      } else {

         if (ua.safari) {

            ua.chrome = /chrome/.test(navigator.userAgent.toLowerCase());

            if (ua.chrome) {

               txt += "Chrome";

            } else {

               txt += "Safari";

            }

         } else {

            if (ua.opera) {

               txt += "Opera";

            } else {

               txt += "not Firefox, IE, Safari, Chrome, or Opera";

            }

         }

      }

   }

   txt += "<br />...versioned at: " + jQuery.browser.version + "</br>";

   txt += "......is insufficient for our application.</p>";

   document.getElementById("badbrowserspecifications").innerHTML = txt;

</script>

 
 

Sources for my change of heart:

No comments:

Post a Comment