Although browser detection is going out of fashion fast, I still use it sometimes to quickly deal with bugs in certain browsers .
This is an example of how you can use the browser object in jQuery to target specific browsers and their versions. The code in the below conditional is only executed when Internet Explorer 6 loads the page:
if ($.browser.msie && $.browser.version.substr(0,1) == 6){ alert('Houston we have an IE6'); }
To detect IE8 you need to use this bit of extra detection since it reports its version string as 7 in most cases.
if ($.browser.msie && navigator.userAgent.indexOf('Trident')!==-1){ /* IE 8 specific code goes here. */ }
Detect IE9 like so:
if ($.browser.msie && parseInt($.browser.version) < 9){ // here goes some code for all Internet Explorer versions older than 9 }
The below code detects safari versions smaller than 3
if($.browser.safari && parseInt($.browser.version.substr(0,1))<5){ alert('deliver us from old safari versions') }
The below allows you to detect Safari versions lower than Safari 4
if($.browser.safari && parseInt($.browser.version.substr(0,2))<53){ alert('deliver us from old safari versions') }
Available flags are: