javascript - Browser & OS as body class -


i have os , browser in body class. need pixelperfect styling, because fonts not behave same way in different os / browser configurations. after googling , experimenting. way think of use indexof...

var osname="unknown os"; if (navigator.appversion.indexof("win")!=-1) osname="windows"; if (navigator.appversion.indexof("mac")!=-1) osname="macos"; if (navigator.appversion.indexof("x11")!=-1) osname="unix"; if (navigator.appversion.indexof("linux")!=-1) osname="linux";  var agt=navigator.useragent.tolowercase(); if (agt.indexof("opera") != -1) return 'opera'; if (agt.indexof("firefox") != -1) return 'firefox'; if (agt.indexof("safari") != -1) return 'safari'; if (agt.indexof("webkit") != -1) return 'webkit'; if (agt.indexof("msie") != -1) return 'internet explorer'; if (agt.indexof("mozilla/5.0") != -1) return 'mozilla'; 

i think not beautyful solution. there regex this? or there faster way this?

you use regex, wouldn't make prettier.

basically, scanning user agent strings browser/os/version never going beautiful.

here little prettier jquery...

// add classes body css hooks  // browser $.each($.browser, function(i) {     $('body').addclass(i);     return false;   });   // os var os = [     'iphone',     'ipad',     'windows',     'mac',     'linux' ];  var match = navigator.appversion.tolowercase().match(new regexp(os.join('|'))); if (match) {     $('body').addclass(match[0]); }; 

this doesn't quite give same classes above, enough differentiate different os , browser.

for example, target firefox on windows with...

body.windows.mozilla {     background: blue; } 

see it!

or use plugin.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -