Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active July 14, 2016 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaming/f4ddada216c74a975b41 to your computer and use it in GitHub Desktop.
Save weaming/f4ddada216c74a975b41 to your computer and use it in GitHub Desktop.
function checkBrowser(){
var br={}
var ua=navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/chrome\/([\d.]+)/)) ? br.chrome = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? br.firefox = s[1] :
(s = ua.match(/msie ([\d.]+)/)) ? br.ie = s[1] :
(s = ua.match(/net.*rv:([\d.]+)/)) ? br.ie = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? br.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? br.safari = s[1] : 0;
var rt = '';
if (br.ie) rt = 'IE: ' + br.ie;
if (br.firefox) rt = 'Firefox: ' + br.firefox;
if (br.chrome) rt = 'Chrome: ' + br.chrome;
if (br.opera) rt = 'Opera: ' + br.opera;
if (br.safari) rt = 'Safari: ' + br.safari;
return rt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment