show a div with jQuery if the user is on IE 9 and below

399 views Asked by At

How could I detect (with jQuery) if the user is on IE 9 or below, and if they are .show() a div?

I have successfully done the below with jQuery for Android. How could I do a IE 9 AND below condition?

Done similar with Android. (would like a similar solution for IE 9 and below)

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
    // alert( "welcome" );
    $("#android").slideDown();
}
2

There are 2 answers

0
Lieutenant Dan On BEST ANSWER

Duh... been a few years, since I busted one of these out..

<!--[if lte IE 9]>
  <style>
    #ie { display: block !important;}
  </style>
<![endif]-->
2
YaBCK On

Have you tried to use this method of detecting if you're using IE?

if ($.browser.msie  && parseInt($.browser.version, 10) > 8)
    console.log('Using IE9/10'); 
else         
    console.log('Not IE9/10');

Another way of doing it because $.browser is deprecated:

checkIEVersion();

/**
 * Returns the version of Internet Explorer or a -1
 * (indicating the use of another browser).
 */
function getIEVersion()
{
    var returnValue = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        var userAgentValue = navigator.userAgent;
        var regExpValue  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (regExpValue.exec(userAgentValue) != null)
            returnValue = parseFloat( RegExp.$1 );
    }

    return returnValue;
}

function checkIEVersion()
{
    var returnMessage = "You're not using Internet Explorer.";
    var ieVersion = getIEVersion();

    if ( ieVersion > -1 )
    {
        if ( ieVersion >= 9.0 ) 
            returnMessage = "You're using a recent copy of Internet Explorer."
        else
            returnMessage = "You should upgrade your copy of Internet Explorer.";
    }

    console.log( returnMessage );
}