Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect IE8, using JQuery? [duplicate]

Tags:

jquery

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

like image 707
Nasir Avatar asked Jan 26 '11 14:01

Nasir


4 Answers

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

if ( isIE8 ) {
    // do stuff
}
like image 196
Šime Vidas Avatar answered Nov 06 '22 17:11

Šime Vidas


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

like image 24
Kris Ivanov Avatar answered Nov 06 '22 16:11

Kris Ivanov


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 ;)

like image 45
gideon Avatar answered Nov 06 '22 15:11

gideon


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
like image 2
Rob Avatar answered Nov 06 '22 17:11

Rob