Browser Selector with JavaScript


/ Published in: JavaScript
Save to your folder(s)

Piece of cake and easy to use


Copy this code and paste it in your HTML
  1. /*
  2. CSS Browser Selector v0.3.4 (Sep 29, 2009)
  3. Rafael Lima (http://rafael.adm.br)
  4. http://rafael.adm.br/css_browser_selector
  5. License: http://creativecommons.org/licenses/by/2.5/
  6. Contributors: http://rafael.adm.br/css_browser_selector#contributors
  7. */
  8. function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}
  9. css_browser_selector(navigator.userAgent);

URL: http://rafael.adm.br/css_browser_selector

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.