Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect older IE versions

I need to detect if the user is running an older version of IE (IE9 is fine) from a jQuery plugin, so I won't have control over the HTML.

We've been discouraged from parsing the user-agent string and using $.browser.msie. The $.support method doesn't cover the problem either.

So, I figured out that this works, but I'm not sure if it is "good practice".

$('body').append('<!--[if lte IE 8]><script>$("body").addClass("oldie");</script><![endif]-->');
var old_ie = $('body').is('.oldie');

Would you use this method or stick with parsing the user-agent string (I'll need to figure out if it's IE and get the version number)?

like image 327
Mottie Avatar asked Aug 29 '11 18:08

Mottie


People also ask

How do I see older versions of Internet Explorer?

IETester IETester is a software that is free to download. It allows you to run your web pages across multiple versions of Internet Explorer, even as low as IE5. 5 It also allows the user to check how the website performs on different browser versions in Windows 10, 7, Vista and XP.

How do you find IE version 32 or 64 bit?

Click on the Help tab at the top. Select About Internet Explorer which will bring up an information window. If the version of IE displays 64-bit Edition, then it is 64-bit IE, otherwise it is a 32-bit browser.

How do I know if I have IE11?

Press the Alt key (next to the Spacebar) on the keyboard to open a menu bar. Click Help and select About Internet Explorer. The IE version is displayed in the pop-up window.


2 Answers

You can run this

var ie = (function () {
    var undef, v = 3, div = document.createElement('div');

    while (
        div.innerHTML = '<!--[if gt IE '+(++v)+']><i></i><![endif]-->',
        div.getElementsByTagName('i')[0]
    );

    return v > 4 ? v : undef;
}());

to detect the version of IE.

Source: http://ajaxian.com/archives/attack-of-the-ie-conditional-comment

And then

if ( ie < 9 ) {
    // do your stuff, for instance:
    window.location = 'http://getfirefox.com'; // :p
}
like image 123
Šime Vidas Avatar answered Oct 18 '22 12:10

Šime Vidas


You didn't explicitly mention in your question why you had a specific need to detect for IE9, so in general the following advice holds:

Rather than detecting for a specific browser / version, you should instead be detecting for specific features. Modernizr is a good place to start for help with this.

like image 21
Raul Agrait Avatar answered Oct 18 '22 13:10

Raul Agrait