How to detect IE7 and below using jQuery.support?

I am currently using jQuery.browser to detect IE7 and below

if ($.browser.msie && parseInt($.browser.version) <= 7) { //codes } 

but jQuery.browser is deprecated in jQuery 1.3 and retired in jQuery 1.9, I read from jQuery that function detection (jQuery.support) should be used instead.

So how to define IE7 and below using jQuery.support?

+6
source share
7 answers

The best way is to use conditional comments and test it with jQuery 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 out IE 7:

 // Check IE 7 if ($('html').hasClass('ie7'); 

This method cannot be faked , no matter what. Also see: Paul Irish Conditional Style Sheets .

+10
source

This little function will tell you if the button code is broken:

 function isButtonBroken() { var b = document.createElement('button'); b.value = 1; b.appendChild(document.createTextNode('2')); return b.value === '12'; } 
+2
source

jQuery.Support does not give you a browser. Starting with jQuery 1.9, the $ .browser function has been deprecated. If your quick way was the easiest way, use your own browsers navigation 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, as the browser can easily “trick” this object. Using a library, such as the Moderizer function for discovery, is a modern approach. For more information, see: 5+ IE VERSION TEST METHODS USING JAVASCRIPT / JQUERY

+1
source

As others have said, trying to detect a browser version is a bad idea, and you should rely on feature detection.

This suggests that the only reliable way to detect the rendering mechanism of the IE browser is to use conditional comments. You can use this little snippet to get it for you:

 var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0] ); return v > 4 ? v : undef; }()); 

Keep in mind that this will only work on versions of IE that support conditional comments , and it will not work on IE10 or higher .

+1
source

The no script solution can be based on providing a button of type submit and a name that is the value you want to send. Then, on the server, make the action dependent on the value of the name attribute, not the value, for example.

 <button type="submit" name="whatever" value="Click me 0">Click me 0</button> 

Now each browser will send the button &whatever=Click+me+0 . I don't have IE 7 for testing, but from what you posted, this should work.

If you have several buttons in the form, only the one that is clicked to submit the form will be successful, so only the name and value of the button will be sent.

Of course, the simplest of these is to use input of type submit, but maybe you cannot do this.

0
source

U Can be detected using the following condition.

 if (!$.support.leadingWhitespace) { //IE7 stuff } 
0
source

You cannot discover the browser using jQuery.support.

Instead of checking the browser, you should check the function of the browsers you want to use.

For example, if you want to use the ajax function, you can check for an XMLHttpRequest object using jQuery.support.ajax

 var ajaxEnabled = $.support.ajax; if (ajaxEnabled) { // do something } 

jQuery.browser document says that

jQuery.browser may be ported to the plugin in a future version of jQuery.

And also says that

Since $ .browser uses navigator.userAgent to determine the platform, it is vulnerable to spoofing the user or distorting the browser itself. It is always best to avoid browser-specific code where possible. The $ .support property is available for detecting support for certain functions, and not for using $ .browser.


You can create your own browser detection code. See below. But keep in mind that this code is vulnerable to spoofing , as the jQuery doc says.

 var ua = navigator.userAgent.toLowerCase(); var isOpera : (ua.indexOf('opera') >= 0) ? true : false; var isFirefox : (ua.indexOf('firefox') >= 0) ? true : false; var isMSIE : (ua.indexOf('msie') >= 0) ? true : false; var isMSIE6 : (ua.indexOf('msie 6.0') >= 0) ? true : false; var isMSIE7 : (ua.indexOf('msie 7.0') >= 0) ? true : false; var isMSIE8 : (ua.indexOf('msie 8.0') >= 0) ? true : false; var isMSIE9 : (ua.indexOf('msie 9.0') >= 0) ? true : false; // and other browsers... 
-1
source

All Articles