Visitor Info (Browser, OS, Window Dimensions, Screen Resolution)


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



Copy this code and paste it in your HTML
  1. //-- Start of Browser, Version and OS
  2. var BrowserDetect = {
  3. init: function () {
  4. this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
  5. this.version = this.searchVersion(navigator.userAgent)
  6. || this.searchVersion(navigator.appVersion)
  7. || "an unknown version";
  8. this.OS = this.searchString(this.dataOS) || "an unknown OS";
  9. },
  10. searchString: function (data) {
  11. for (var i=0;i<data.length;i++) {
  12. var dataString = data[i].string;
  13. var dataProp = data[i].prop;
  14. this.versionSearchString = data[i].versionSearch || data[i].identity;
  15. if (dataString) {
  16. if (dataString.indexOf(data[i].subString) != -1)
  17. return data[i].identity;
  18. }
  19. else if (dataProp)
  20. return data[i].identity;
  21. }
  22. },
  23. searchVersion: function (dataString) {
  24. var index = dataString.indexOf(this.versionSearchString);
  25. if (index == -1) return;
  26. return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  27. },
  28. dataBrowser: [
  29. {
  30. string: navigator.userAgent,
  31. subString: "Chrome",
  32. identity: "Chrome"
  33. },
  34. { string: navigator.userAgent,
  35. subString: "OmniWeb",
  36. versionSearch: "OmniWeb/",
  37. identity: "OmniWeb"
  38. },
  39. {
  40. string: navigator.vendor,
  41. subString: "Apple",
  42. identity: "Safari",
  43. versionSearch: "Version"
  44. },
  45. {
  46. prop: window.opera,
  47. identity: "Opera"
  48. },
  49. {
  50. string: navigator.vendor,
  51. subString: "iCab",
  52. identity: "iCab"
  53. },
  54. {
  55. string: navigator.vendor,
  56. subString: "KDE",
  57. identity: "Konqueror"
  58. },
  59. {
  60. string: navigator.userAgent,
  61. subString: "Firefox",
  62. identity: "Firefox"
  63. },
  64. {
  65. string: navigator.vendor,
  66. subString: "Camino",
  67. identity: "Camino"
  68. },
  69. { // for newer Netscapes (6+)
  70. string: navigator.userAgent,
  71. subString: "Netscape",
  72. identity: "Netscape"
  73. },
  74. {
  75. string: navigator.userAgent,
  76. subString: "MSIE",
  77. identity: "Explorer",
  78. versionSearch: "MSIE"
  79. },
  80. {
  81. string: navigator.userAgent,
  82. subString: "Gecko",
  83. identity: "Mozilla",
  84. versionSearch: "rv"
  85. },
  86. { // for older Netscapes (4-)
  87. string: navigator.userAgent,
  88. subString: "Mozilla",
  89. identity: "Netscape",
  90. versionSearch: "Mozilla"
  91. }
  92. ],
  93. dataOS : [
  94. {
  95. string: navigator.platform,
  96. subString: "Win",
  97. identity: "Windows"
  98. },
  99. {
  100. string: navigator.platform,
  101. subString: "Mac",
  102. identity: "Mac"
  103. },
  104. {
  105. string: navigator.userAgent,
  106. subString: "iPhone",
  107. identity: "iPhone/iPod"
  108. },
  109. {
  110. string: navigator.platform,
  111. subString: "Linux",
  112. identity: "Linux"
  113. }
  114. ]
  115.  
  116. };
  117. BrowserDetect.init();
  118.  
  119. //-- Start of Window Dimensions
  120. var winW = 0, winH = 0;
  121. if( typeof( window.innerWidth ) == 'number' ) {
  122. //Non-IE
  123. winW = window.innerWidth;
  124. winH = window.innerHeight;
  125. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  126. //IE 6+ in 'standards compliant mode'
  127. winW = document.documentElement.clientWidth;
  128. winH = document.documentElement.clientHeight;
  129. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  130. //IE 4 compatible
  131. winW = document.body.clientWidth;
  132. winH = document.body.clientHeight;
  133. }
  134.  
  135. //-- Start of Screen Resolution
  136. var vertical=screen.height
  137. var horizontal=screen.width

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.