Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created January 17, 2010 12:36
Show Gist options
  • Save cowboy/279354 to your computer and use it in GitHub Desktop.
Save cowboy/279354 to your computer and use it in GitHub Desktop.
function jquery_14_useragent_test( ua ) {
var ret = { browser: "" };
ua = ua.toLowerCase();
if ( /webkit/.test( ua ) ) {
ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };
} else if ( /opera/.test( ua ) ) {
ret = { browser: "opera", version: /version/.test( ua ) ? /version[\/ ]([\w.]+)/ : /opera[\/ ]([\w.]+)/ };
} else if ( /msie/.test( ua ) ) {
ret = { browser: "msie", version: /msie ([\w.]+)/ };
} else if ( /mozilla/.test( ua ) && !/compatible/.test( ua ) ) {
ret = { browser: "mozilla", version: /rv:([\w.]+)/ };
}
ret.version = (ret.version && ret.version.exec( ua ) || [0, "0"])[1];
return ret;
}
function my_useragent_test( ua ) {
var matches;
ua = ua.toLowerCase();
if ( matches = /(webkit)[ \/]([\w.]+)/.exec( ua ) ) {
} else if ( matches = /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ) {
} else if ( matches = /(msie) ([\w.]+)/.exec( ua ) ) {
} else if ( !/compatible/.test( ua ) && ( matches = /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ) ) {
} else {
matches = [];
}
return { browser: matches[1] || "", version: matches[2] || "0" };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment