Browser Checker


/ Published in: JavaScript
Save to your folder(s)

Support: Fx2, Opera9, IE6
I don't have warrant of Safari's run and NN4. However, I think that this code is perhaps safe.


Copy this code and paste it in your HTML
  1. /*-----------------------------------------------------------------------------
  2.  * Navigator
  3.  * Example Source
  4. document.write(
  5. (Navigator.isWinIE()) ? 'IE' + Navigator.isWinIE() + ' (Win)' :
  6. (Navigator.isMacIE()) ? 'IE' + Navigator.isMacIE() + ' (Mac)' :
  7. (Navigator.isGecko()) ? 'Mozilla (' + Navigator.isGecko() + ')' :
  8. (Navigator.isSafari()) ? 'Safari (' + Navigator.isSafari() + ')' :
  9. (Navigator.isKDE()) ? 'KDE (' + Navigator.isKDE() + ')' :
  10. (Navigator.isOpera()) ? 'Opera' + Navigator.isOpera() :
  11. (Navigator.isNN4()) ? 'NN4' :
  12. "I don't know."
  13. );
  14.  *-------------------------------------------------------------------------- */
  15.  
  16. var Navigator = {
  17. _getVersion: function (a, b) {
  18. var t = navigator.userAgent.split(a)[1];
  19. return (t) ? t.split(b)[0] : false;
  20. },
  21. isOpera: function () {
  22. return (
  23. (window.opera) ?
  24. (document.createElementNS) ?
  25. (document.createCDATASection) ?
  26. (document.styleSheets) ? 9 : 8
  27. : 7
  28. : 6
  29. : false
  30. );
  31. },
  32. isSafari: function () {
  33. return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('AppleWebKit/', '(') : false;
  34. },
  35. isKDE: function () {
  36. return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Konqueror/', ';') : false;
  37. },
  38. isGecko: function () {
  39. return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Gecko/', ' ') : false;
  40. },
  41. isNN4: function () {
  42. return (document.layers && typeof document.layers == 'object') ? true : false;
  43. },
  44. isWinIE: function () {
  45. return (
  46. /*@cc_on @if (@_win64 || @_win32 || @_win16)
  47. (document.getElementsByTagName) ?
  48. (@_jscript_version > 5.6) ? 7 :
  49. (@_jscript_version == 5.6) ? 6 :
  50. (@_jscript_version == 5.5) ? 5.5 :
  51. 5
  52. : 4
  53. @else@*/false/*@end @*/
  54. );
  55. },
  56. isMacIE: function () {
  57. return (
  58. /*@cc_on @if (@_mac && (@_PowerPC || @_mc680x0))
  59. (document.getElementsByTagName) ? 5 : 4
  60. @else@*/false/*@end @*/
  61. );
  62. }
  63. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.