Tuesday, August 28, 2012

Javascript: detection browser type



To detect the browser type in JavaScript: (>-1 shows the bowser type)

           var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox');
           var is_msie = navigator.userAgent.toLowerCase().indexOf('msie');
           var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome'); 
           var is_safari = navigator.userAgent.toLowerCase().indexOf('safari'); 
          if(is_firefox>-1)
           {
                     alert("Your browser is FireFox");
           }
          else if(is_msie>-1)
          {
                       alert("Your browser is MSIE");

           }
           else if(is_chrome>-1)
           {
                      alert("Your browser is Chrome");
           }

          elseif(is_safari>-1)
         {
                       alert("Your browser is Safari");
          }

Although Safari is originally from Mac, you can download it for Windows:
http://support.apple.com/downloads/Safari_3_2_2_for_Windows

All these 4 browsers can be tested in Windows.


No comments:

Post a Comment