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)?
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.
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.
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.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With