Posted By

chrisaiv on 10/18/08


Tagged

browser jquery sniffer


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

jdstraughan
rwczippy
zoblue
LeslieOA
jonathanpglick
flicity
masondixon
seanpowell
allproweb
Snowalker
delirium


JQuery: Common Browser Sniffing


 / Published in: JavaScript
 

There have been a few times where I've been forced to reduce myself to browser sniffing. In this example, I'm making an ad hoc change to CSS but for anyone interested in making changes to IE6/IE7 only, there's a better way. Take a look at my other snippet. http://snipplr.com/view/9095/html-conditional-html-for-ie6-and-ie7/

  1. //A. Target Safari
  2. if( $.browser.safari ) $("#menu li a").css("padding", "1em 1.2em" );
  3.  
  4. //B. Target anything above IE6
  5. if ($.browser.msie && $.browser.version > 6 ) $("#menu li a").css("padding", "1em 1.8em" );
  6.  
  7. //C. Target IE6 and below
  8. if ($.browser.msie && $.browser.version <= 6 ) $("#menu li a").css("padding", "1em 1.8em" );
  9.  
  10. //D. Target Firefox 2 and above
  11. if ($.browser.mozilla && $.browser.version >= "1.8" ) $("#menu li a").css("padding", "1em 1.8em" );

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jdstraughan on December 9, 2008

Works great!

Posted By: jdstraughan on December 9, 2008

Works great!

Posted By: Snowalker on December 5, 2011

umm this can be useful as an alternative to IE conditional comments. Fav! :)

Posted By: chrisaiv on December 24, 2011

@Snowalker, I agree completely. That's why I also suggest looking at my conditionals snippet. http://snipplr.com/view/9095/html-conditional-html-for-ie6-and-ie7/

You need to login to post a comment.