6

Possible Duplicate:
how do i detect ie 8 with jquery

Hi All,

I was on here looking for a JQuery snippet to detect IE8. This is what I found, see below:

    if(jQuery.browser.version.substring(0, 2) == "8.") { 
        $('#step-1').css({'margin-left':'8px'});
     }

I found this but it doesnt seem to be working...Can someone advise me where I might be going wrong...or have other suggestions.

Thanks

Community
  • 1
  • 1
Nasir
  • 4,785
  • 10
  • 35
  • 39
  • 2
    Browser detection is usually a bad thing to do. If you have differences in how browser display your CSS, then there are usually better ways to correct that, but you'd have to explain the actual problem more closely. – RoToRa Jan 26 '11 at 14:55
  • @RoToRa - You're right it's a CSS problem – Nasir Jan 26 '11 at 14:59

4 Answers4

13
var isIE8 = $.browser.msie && +$.browser.version === 8;

if ( isIE8 ) {
    // do stuff
}
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
8

use $.browser.msie for detecting IE and $.browser.version for getting the version

Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35
5

See the following SO questions:

How do I detect IE 8 with jQuery?
When IE8 is not IE8 what is $.browser.version?
Detect IE6 with Jquery

Try and use the ninja search. http://www.stackoverflow.com/search

I set the google stackoverflow search with a keyword "so" on Google Chrome, found those questions in 3 secs ;)

Community
  • 1
  • 1
gideon
  • 19,329
  • 11
  • 72
  • 113
2

Jquery has default functionality for this. You can read about it here.

For example:

<script>
    jQuery.each(jQuery.browser, function(i, val) {
      $("<div>" + i + " : <span>" + val + "</span>")
                .appendTo(document.body);
    });
</script>

Which will result in;

MSIE : true
version : 8.0
Rob
  • 6,731
  • 12
  • 52
  • 90