Skip to content

Instantly share code, notes, and snippets.

@gary-rafferty
Created January 27, 2012 13:15
Show Gist options
  • Save gary-rafferty/1688715 to your computer and use it in GitHub Desktop.
Save gary-rafferty/1688715 to your computer and use it in GitHub Desktop.
Quick jquery plugin to check navigator.userAgent string
(function($){
function getInternetExplorerVersion() {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
$.extend({
eyebrowser: function() {
var agentString = navigator.userAgent.toString();
if(/Chrome/.test(agentString)) {
return "Chrome";
} else if(/Firefox/.test(agentString)){
return "Firefox";
} else if(/MSIE/.test(agentString)) {
var iev = getInternetExplorerVersion();
return "IE "+iev;
} else if(/Opera/.test(agentString)) {
return "Opera";
} else {
return "Other browser";
}
}
});
})(jQuery)
// alert($.eyebrowser());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment