Dimitri Vorontzov Dimitri Vorontzov - 9 days ago 5
jQuery Question

jQuery: Target ONLY Safari

I'm using this bit of jQuery code to target Safari:

if ($.browser.safari) {
$('#div1').css({'margin-top': '-22px'});
$('#div2').css({'margin-top': '-17px'});
}


Oddly, it also targets Chrome (at least Mac version). What jQuery code can I use that would ignore Chrome and target only Safari?

I would be grateful for expert advice.

Answer

(Edit so that Chrome must not be in the user agent):

if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1)  { 
   //i.e. apply safari class via jquery
}