JQuery $. support gets the browser name and version information

Source: Internet
Author: User

In jQuery, use $. the browser object can obtain the name and version of the browser, for example, $. browser. chrome is true, indicating the current Chrome browser, $. browser. mozilla is true, indicating that the Firefox browser is currently available. You can also use $. browser. to obtain the browser version information.

The code is as follows: Copy code

<Div id = "divtest">
<Div class = "title">
<Span class = "fl"> Get the browser name and version number </span>
</Div>
<Div class = "content"> </div>
</Div>
       
<Script type = "text/javascript">
$ (Function (){
Var strTmp = "your browser name is :";
If ($. browser. chrome) {// Google chrome
StrTmp + = "Chrome ";
               }
If ($. browser. mozilla) {// Firefox related browsers
StrTmp + = "Mozilla FireFox ";
               }
StrTmp + = "<br/> the version number is:" // get the version number
+ ?;
$ (". Content" pai.html (strTmp );
});
</Script>

Check whether the object is empty
 
In jQuery, you can call $. the tool function of isEmptyObject checks whether the content of an object is null. If it is null, the function returns true. Otherwise, the system returns false. The Call format is as follows:

$. IsEmptyObject (obj );

The obj parameter indicates the name of the object to be detected.
 

The code is as follows: Copy code
<Div id = "divtest">
<Div class = "title">
<Span class = "fl"> Check whether the object is empty </span>
</Div>
<Div class = "content"> </div>
</Div>
      
<Script type = "text/javascript">
$ (Function (){
Var obj = {"name": "Local tyrants "};
Var strTmp = "You have defined one :";
If ($. isEmptyObject (obj) {// check whether it is empty
StrTmp + = "empty object ";
              }
Else {
StrTmp + = "non-empty object ";
              }
$ (". Content" pai.html (strTmp );
});
</Script>

 
Check whether the object is the original object

The call name is $. the tool function of isPlainObject can detect whether the Object is an original Object created using the {} or new Object () keyword. If yes, true is returned. Otherwise, false is returned. The Call format is:
$. IsPlainObject (obj );
The obj parameter indicates the name of the object to be detected.

JQuery has removed $. browser and $. browser. version from version 1.9 and replaced it with the $. support method. For more information about $. support, see:

JQuery 1.9 replaces $. support with the $. browser method.


Use $. support to determine the browser! Test the following code:

The code is as follows: Copy code

Alert ($. support. opacity + "" + $. support. style + "" + window. XMLHttpRequest );

Ie6: false undefind

Ie7: false object

Ie8: false true object

Ie9: true object

SO, judge the browser: alert ($. support. opacity + "" + $. support. style + "" + window. XMLHttpRequest );

Var isIE6 =! $. Support. opacity &&! $. Support. style & window. XMLHttpRequest = undefined;

Var isIE7 =! $. Support. opacity &&! $. Support. style & window. window. XMLHttpRequest! = Undefined;

Var isIE67 =! $. Support. opacity &&! $. Support. style; // ie6 \ 7

If you want to check ie, simply use var isIE =/msie/. test (navigator. userAgent. toLowerCase ());

Of course, you can also use pure js to detect

The code is as follows: Copy code

Function isBrowser (){
Var Sys = {};
Var ua = navigator. userAgent. toLowerCase ();
Var s;
(S = ua. match (/msie ([\ d.] + )/))? Sys. ie = s [1]:
(S = ua. match (/firefox \/([\ d.] + )/))? Sys. firefox = s [1]:
(S = ua. match (/chrome \/([\ d.] + )/))? Sys. chrome = s [1]:
(S = ua. match (/opera. ([\ d.] + )/))? Sys. opera = s [1]:
(S = ua. match (/version \/([\ d.] +). * safari /))? Sys. safari = s [1]: 0;
If (Sys. ie) {// Js judge as ie browser
Alert ('http: // www.111cn.net '+ Sys. ie );
If (Sys. ie = '9. 0') {// Js determines it is IE 9
} Else if (Sys. ie = '8. 0') {// Js determines it as IE 8
} Else {
        }
    }
If (Sys. firefox) {// Js judge as firefox
Alert ('http: // www.111cn.net '+ Sys. firefox );
    }
If (Sys. chrome) {// Js judge as Google chrome
Alert ('http: // www.111cn.net '+ Sys. chrome );
    }
If (Sys. opera) {// Js judge as operabrowser
Alert ('http: // www.111cn.net '+ Sys. opera );
    }
If (Sys. safari) {// Js determines it is an Apple safari browser
Alert ('http: // www.111cn.net '+ Sys. safari );
    }
}

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.