0

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();
}
fred randall
  • 7,023
  • 18
  • 73
  • 167
  • 2
    can you try this? if ($.browser.msie && parseInt($.browser.version, 10) < 9) – Sushil Jun 10 '15 at 19:27
  • 2
    possible duplicate of [Browser detection in JavaScript?](http://stackoverflow.com/questions/2400935/browser-detection-in-javascript) – talemyn Jun 10 '15 at 19:28
  • I'm looking for a short jQuery solution as Sushil is recommending, and like one i referenced, not a long old school javascript technique to isolate every browser user string, defining individually; but something simple, like if this or below. – fred randall Jun 10 '15 at 19:32
  • 1
    you can also try if (document.addEventListener) { alert("IE9 or greater"); } – Sushil Jun 10 '15 at 20:01

2 Answers2

3

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 );
}
YaBCK
  • 3,205
  • 3
  • 26
  • 52
0

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

<!--[if lte IE 9]>
  <style>
    #ie { display: block !important;}
  </style>
<![endif]-->
fred randall
  • 7,023
  • 18
  • 73
  • 167