jquery Judge Browser version plugin, jquery-browser.js

Source: Internet
Author: User

First, jquery judge browser version plugin, jquery-browser.js

After jquery 1.9 has deleted the method of judging the browser version:



$.browser.version

The reasons are:

Note: It is not a good idea to detect the browser through the user agent string, and the method will be completely removed in 1.9, but you can use the jquery Migrate (migration) plugin. Or you can try Modernizr.

But what if you want to use it?

Second, the solution:

Copy the following code, save as Jquery-browser.js, add jquery-browser.js under Jquery.js, you can use jquery to delete the browser version of the method of judging.

The attached file is also available for direct download.

(function(jQuery) {if(Jquery.browser)return; Jquery.browser= {}; JQuery.browser.mozilla=false; JQuery.browser.webkit=false; JQuery.browser.opera=false; JQuery.browser.msie=false; varNAGT =navigator.useragent; JQuery.browser.name=Navigator.appname; JQuery.browser.fullVersion= ' +parsefloat (navigator.appversion); JQuery.browser.majorVersion= parseint (navigator.appversion, 10); varNameoffset, Veroffset, IX; //in Opera, the true version was after "Opera" or after "version"        if((Veroffset = Nagt.indexof ("Opera"))! =-1) {JQuery.browser.opera=true; JQuery.browser.name= "Opera"; JQuery.browser.fullVersion= nagt.substring (Veroffset + 6); if((Veroffset = Nagt.indexof ("Version"))! =-1) JQuery.browser.fullVersion= nagt.substring (Veroffset + 8); }          //in MSIE, the true version was after ' MSIE ' in useragent        Else if((Veroffset = Nagt.indexof ("MSIE"))! =-1) {JQuery.browser.msie=true; JQuery.browser.name= "Microsoft Internet Explorer"; JQuery.browser.fullVersion= nagt.substring (Veroffset + 5); }          //in Chrome, the true version was after "Chrome"        Else if((Veroffset = Nagt.indexof ("Chrome"))! =-1) {JQuery.browser.webkit=true; JQuery.browser.name= "Chrome"; JQuery.browser.fullVersion= nagt.substring (Veroffset + 7); }          //in Safari, the true version was after "Safari" or after "version"        Else if((Veroffset = Nagt.indexof ("Safari"))! =-1) {JQuery.browser.webkit=true; JQuery.browser.name= "Safari"; JQuery.browser.fullVersion= nagt.substring (Veroffset + 7); if((Veroffset = Nagt.indexof ("Version"))! =-1) JQuery.browser.fullVersion= nagt.substring (Veroffset + 8); }          //in Firefox, the true version was after "Firefox"        Else if((Veroffset = Nagt.indexof ("Firefox"))! =-1) {JQuery.browser.mozilla=true; JQuery.browser.name= "Firefox"; JQuery.browser.fullVersion= nagt.substring (Veroffset + 8); }          //in the very other browsers, "Name/version" are at the end of the useragent        Else if(Nameoffset = Nagt.lastindexof (') + 1) < (Veroffset =nagt. LastIndexOf (‘/‘)) {jQuery.browser.name=nagt.substring (Nameoffset, Veroffset); JQuery.browser.fullVersion= nagt.substring (Veroffset + 1); if(jQuery.browser.name.toLowerCase () = =jQuery.browser.name. toUpperCase ()) {JQuery.browser.name=Navigator.appname; }          }          //Trim the fullversion string at semicolon/space if present        if(ix = jQuery.browser.fullVersion.indexOf (";"))!! =-1) JQuery.browser.fullVersion=jQuery.browser.fullVersion. Substring (0, ix); if(ix = jQuery.browser.fullVersion.indexOf (""))! =-1) JQuery.browser.fullVersion=jQuery.browser.fullVersion. Substring (0, ix); JQuery.browser.majorVersion= parseint (' + jQuery.browser.fullVersion, 10); if(IsNaN (jQuery.browser.majorVersion)) {jQuery.browser.fullVersion= ' +parsefloat (navigator.appversion); JQuery.browser.majorVersion= parseint (navigator.appversion, 10); } jQuery.browser.version=jQuery.browser.majorVersion;  }) (JQuery); 

In addition, there is another plugin on the internet, the principle is the same. I have not tested, first recorded here:

Jquery.extend ({browser:function()           {              varRwebkit=/(WebKit) \ ([\w.] +)/, Ropera=/(opera) (?:. *version)? [ \/] ([\w.] +)/, Rmsie=/(MSIE) ([\w.] +)/, Rmozilla=/(Mozilla) (?:. * RV: [\w.] +))?/, Browser={}, UA=window.navigator.userAgent, Browsermatch=Uamatch (UA); if(Browsermatch.browser) {Browser[browsermatch.browser]=true; Browser.version=browsermatch.version; }              return{Browser:browser};            },      }); functionUamatch (UA) {UA=ua.tolowercase (); varMatch =rwebkit.exec (UA)||ropera.exec (UA)||rmsie.exec (UA)|| Ua.indexof ("compatible") < 0 &&rmozilla.exec (UA)|| []; return{browser:match[1] | | "", version:match[2] | | "0"              }; }  

: Address 1

Article from: http://fanshuyao.iteye.com/blog/2312963

jquery Judge Browser version plugin, jquery-browser.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.