No support of $.browser in jQuery 1.9

  sonic0002        2013-08-27 03:10:12       5,211        0    

Starting from jQuery 1.9, $.browser is no longer supported to detect the nrpwser type and version. The substitute is $.support. In the newer jQuery 2.x versions, IE 6/7/8 are also not supported. If users want to support IE 6/7/8, they must use jQuery 1.9. If you want to fully support IE and want to use jQuery 1.9 and jQuery 2.0, the official solution is:

<!--[if lt IE 9]>
    <script src='jquery-1.9.0.js'></script>
<![endif]-->
<!--[if gte IE 9]>
    <script src='jquery-2.0.0.js'></script>
<![endif]-->

For the long run, this can help in browser feature detection in a complicated situation. Many old programs mayy not be able to migrate to the new jQuery without refactoring their codes. The substitutes for $.browser can be :

Check browser type:

$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());
$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());

The expression after the equals sign will return true/false, they can be directly used to replace $.browser.msie etc.

Check whether it's IE 6:

// Old
if ($.browser.msie && 7 > $.browser.version) {}
// New
if ('undefined' == typeof(document.body.style.maxHeight)) {}

Check whether it's IE 6-8:

if (!$.support.leadingWhitespace) {}

The ultimate solution is to use other library such as this one. But we recommend detecting browser type as the last step to choose for implementing cross browser solutions.

Source : http://www.fwolf.com/blog/post/35

JQUERY  $.BROWSER  $.BROWSER.VERSION 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

Password is used by another user