Skip to content

Instantly share code, notes, and snippets.

@christopherhein
Created April 29, 2011 04:37
Show Gist options
  • Save christopherhein/947843 to your computer and use it in GitHub Desktop.
Save christopherhein/947843 to your computer and use it in GitHub Desktop.
Extending Moderizer so that is adds browsers and operating systems
(function($){
$(function() {
var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
chrome: /chrome/.test( userAgent ),
safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
$.each($.browser, function(i, val) { if(val) { $("html").addClass(i) } });
var osname = "unknownos";
if ( navigator.appVersion.indexOf("Win") !=-1 ) osname = "windows";
if ( navigator.appVersion.indexOf("Mac") !=-1 ) osname = "mac";
if ( navigator.appVersion.indexOf("X11") !=-1 ) osname = "unix";
if ( navigator.appVersion.indexOf("Linux") !=-1 ) osname = "linux";
$("html").addClass(osname);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment