Skip to content

Instantly share code, notes, and snippets.

@alejandrorangel
Last active July 20, 2018 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrorangel/e6c31177047dbcc16ae512f02064edd7 to your computer and use it in GitHub Desktop.
Save alejandrorangel/e6c31177047dbcc16ae512f02064edd7 to your computer and use it in GitHub Desktop.
function detectBrowser(userAgent){
var chrome = /.*(Chrome\/).*(Safari\/).*/g;
var firefox = /.*(Firefox\/).*/g;
var safari = /.*(Version\/).*(Safari\/).*/g;
var opera = /.*(Chrome\/).*(Safari\/).*(OPR\/).*/g;
var edge = /.*(Chrome\/).*(Safari\/).*(Edge\/).*/g;
var ie = /.*(Trident\/7).*(rv:).*/g;
if(opera.exec(userAgent))
return "Opera";
if(edge.exec(userAgent))
return "Edge";
if(chrome.exec(userAgent))
return "Chrome";
if(safari.exec(userAgent))
return "Safari";
if(firefox.exec(userAgent))
return "Firefox";
if(ie.exec(userAgent))
return "Internet Explorer";
return "not supported";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment