Solve the problem that jquery1.9 does not support browser objects _ jquery

Source: Internet
Author: User
Jquery1.9 is always used in the project, and browser objects are not supported. Baidu once found the solution. Here we will share with you that if you have encountered this problem, do not miss the recent project requirements, the cycle plug-in of jquery is used, but jquery1.9 is always used in the project. browser objects are not supported. Baidu finds the solution.

Add the following code to the source code of the cycle plug-in:

The Code is as follows:


(Function (jQuery ){

If (jQuery. browser) return;

JQuery. browser = {};
JQuery. browser. mozilla = false;
JQuery. browser. webkit = false;
JQuery. browser. opera = false;
JQuery. browser. msie = false;

Var nAgt = navigator. userAgent;
JQuery. browser. name = navigator. appName;
JQuery. browser. fullVersion = ''+ parseFloat (navigator. appVersion );
JQuery. browser. majorVersion = parseInt (navigator. appVersion, 10 );
Var nameOffset, verOffset, ix;

// In Opera, the true version is 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 is 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 is 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 is 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 is 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 most other browsers, "name/version" is at the end of 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 );


This Code specifically solves the problem that browser objects are not supported.

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.