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'); 
                     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");

                       alert("Your browser is Safari");

Although Safari is originally from Mac, you can download it for Windows:

All these 4 browsers can be tested in Windows.

No comments:

Post a Comment