Currently I'm using jQuery.browser to detect IE7 and lower
if ($.browser.msie && parseInt($.browser.version) <= 7) {
//codes
}
but jQuery.browser was deprecated in jQuery 1.3 and removed in jQuery 1.9, I read from jQuery website that we should use feature detection instead (jQuery.support).
So, how to detect IE7 and lower using jQuery.support?
The best way is to use conditional comments and check it using jQuery's hasClass()
.
<!--[if lt IE 7]> <html class="ie6"> <![endif]-->
<!--[if IE 7]> <html class="ie7"> <![endif]-->
<!--[if IE 8]> <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
And in your jQuery, check for IE 7:
// Check IE 7
if ($('html').hasClass('ie7');
This method cannot be spoofed no matter what. Also see: Conditional Stylesheets by Paul Irish.
This small function will tell you whether the button code is broken:
function isButtonBroken()
{
var b = document.createElement('button');
b.value = 1;
b.appendChild(document.createTextNode('2'));
return b.value === '12';
}
jQuery.Support does not give you the browser. As of jQuery 1.9 the $.browser function is deprecated. If your after a quick was the easiest way is to use the browsers native navigator object.
//check for IE7
if(navigator.appVersion.indexOf("MSIE 7.")!=-1)
Using Modernizr
//check for IE7 or less
if ($('html').hasClass('lt-ie7');
This is not recommended however as the browser can easily "spoof" this object. Using a library such as Moderizer to feature detect is modern approach. For more details info see: 5+ WAYS TO CHECK IE VERSION USING JAVASCRIPT/JQUERY
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