Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. function getBrowser() {
  2. var userAgent = navigator.userAgent,
  3. matched = userAgent.match(/(chrome|firefox|opera|safari|msie|trident(?=/))/?s*(d+)/i) || [],
  4. version,
  5. browser = { name: '', version: '' };
  6.  
  7. // IE Shells; I gaurantee that you will see this with Dell branded OEM IE 11 installs.
  8. if(/trident/i.test(matched[1])) {
  9. version = /brv[ :]+(d+)/g.exec(userAgent) || [];
  10.  
  11. return { name: 'Internet Explorer', version: (version[1] || '') };
  12. }
  13.  
  14. // Not Chrome; at first glance this looks like a block for chrome identification, but
  15. // its actually Opera.
  16. if(matched[1] === 'Chrome') {
  17. version = userAgent.match(/b(OPR|Edge)/(d+)/);
  18.  
  19. if(version !== null) {
  20. return { name: version[1].replace('OPR', 'Opera'), version: version[2] };
  21. }
  22. }
  23.  
  24. // The rest; Chrome, Safari, etc
  25. matched = matched[2] ? [matched[1], matched[2]] : [navigator.appName, navigator.appVersion, '-?'];
  26.  
  27. if((version = userAgent.match(/version/(d+)/i)) !== null) {
  28. matched.splice(1, 1, version[1]);
  29. }
  30.  
  31. browser.name = (matched[0] !== "") ? matched[0] : "Unknown";
  32. browser.version = (matched[1] !== "") ? matched[1] : "Unknown";
  33.  
  34. return browser;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement