We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

Abe on 01/29/08


Tagged


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

jonhenshaw
adix
DeadLy
blackabee


Detect Browser


Published in: JavaScript 


  1. // Browser Detection Javascript
  2. // copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd
  3.  
  4. // You have permission to copy and use this javascript provided that the content of the script is not changed in any way.
  5.  
  6. function whichBrs() {
  7. var agt=navigator.userAgent.toLowerCase();
  8. if (agt.indexOf("opera") != -1) return 'Opera';
  9. if (agt.indexOf("staroffice") != -1) return 'Star Office';
  10. if (agt.indexOf("webtv") != -1) return 'WebTV';
  11. if (agt.indexOf("beonex") != -1) return 'Beonex';
  12. if (agt.indexOf("chimera") != -1) return 'Chimera';
  13. if (agt.indexOf("netpositive") != -1) return 'NetPositive';
  14. if (agt.indexOf("phoenix") != -1) return 'Phoenix';
  15. if (agt.indexOf("firefox") != -1) return 'Firefox';
  16. if (agt.indexOf("safari") != -1) return 'Safari';
  17. if (agt.indexOf("skipstone") != -1) return 'SkipStone';
  18. if (agt.indexOf("msie") != -1) return 'Internet Explorer';
  19. if (agt.indexOf("netscape") != -1) return 'Netscape';
  20. if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
  21. if (agt.indexOf('\/') != -1) {
  22. if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
  23. return navigator.userAgent.substr(0,agt.indexOf('\/'));}
  24. else return 'Netscape';} else if (agt.indexOf(' ') != -1)
  25. return navigator.userAgent.substr(0,agt.indexOf(' '));
  26. else return navigator.userAgent;
  27. }

Report this snippet 

You need to login to post a comment.