Skip to content

Instantly share code, notes, and snippets.

@gluschenko
Created March 19, 2017 16:14
Show Gist options
  • Save gluschenko/c722b2e7957e52244da78e32d8bba3b4 to your computer and use it in GitHub Desktop.
Save gluschenko/c722b2e7957e52244da78e32d8bba3b4 to your computer and use it in GitHub Desktop.
function get_browser_info(){
var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
//console.log(M[0]+" "+M[1]);
if(/trident/i.test(M[1])){
tem=/\brv[ :]+(\d+)/g.exec(ua) || [];
return {name:'IE',version:(tem[1]||'')};
}
if(M[1]==='Chrome'){
tem=ua.match(/\bOPR\/(\d+)/)
if(tem!=null) {return {name:'Opera', version:tem[1], chromeversion: M[2]};}
// next
tem=ua.match(/\bAmigo\/(\d+)/)
if(tem!=null) {return {name:'Amigo', version:tem[1], chromeversion: M[2]};}
// next
tem=ua.match(/\bYaBrowser\/(\d+)/)
if(tem!=null) {return {name:'Yandex', version:tem[1], chromeversion: M[2]};}
for (var i=0; i<navigator.plugins.length; i++)
if (navigator.plugins[i].name == 'Chromium PDF Viewer') {return {name:'Chromium', version:tem[1], chromeversion: M[2]};}
}
M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);}
return {
name: M[0],
version: M[1]
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment