Determine the browser's kernel and version number method Rollup _jquery

Source: Internet
Author: User

Using jquery to determine the kernel and version number of the browser

Copy Code code as follows:

<script type= "Text/javascript" >
$ (function () {
if ($.browser.msie && ($.browser.version = = "7.0")) {
$ ("#yourannet"). CSS ("Margin-left", "10px");
}//ie7 Browser
else if ($.browser.msie && ($.browser.version = = "6.0") &&!$.support.style) {
$ ("#yourannet"). CSS ("Margin-left", "15px");
}//ie6 Browser
else if ($.browser.msie && ($.browser.version = = "8.0")) {
$ ("#yourannet"). CSS ("Margin-left", "20px");
}//IE8 Browser
else if ($.browser.msie && ($.browser.version = = "9.0")) {
$ ("#yourannet"). CSS ("Margin-left", "25px");
}//IE9 browser
else if (Window.navigator.userAgent.toLowerCase (). IndexOf ("360SE") >= 1) {
$ ("#yourannet"). CSS ("Margin-left", "30px");
}//360 Browser
})

JQuery uses the regular to match useragent to determine the type and version of the browser . What if we're going to judge whether the current browser is IE6?

Copy Code code as follows:

$ (function () {
if ($.browser.msie) {
Alert ("This is Msie");
}
else if ($.browser.safari)
{
Alert ("This is safari!");
}
else if ($.browser.mozilla)
{
Alert ("This is mozilla!");
}
else if ($.browser.opera) {
Alert ("This is opera");
}
else {
Alert ("I don ' t konw!");
}

The following is a regular expression of jquery: support for distinguishing ie, Firefox, opera, Chrome, Safari

Copy Code code as follows:

Browser Check-----start
var useragent = navigator.useragent,//useragent
Rmsie =/.* (MSIE) ([\w.] +). */,//IE
Rfirefox =/.* (Firefox) \/([\w.] +). */,//Firefox
Ropera =/(opera). +version\/([\w.] +)/,//Opera
Rchrome =/.* (Chrome) \/([\w.] +). */,//Chrome
Rsafari =/.*version\/([\w.] +). * (Safari). */;//Safari
Jmeteor.browser = {};
var ua = Useragent.tolowercase ();
function Uamatch (UA) {
var match = rmsie.exec (UA);
if (match!= null) {
return {browser:match[1]¦¦ "", version:match[2]¦¦ "0"};
}
var match = rfirefox.exec (UA);
if (match!= null) {
return {browser:match[1]¦¦ "", version:match[2]¦¦ "0"};
}
var match = ropera.exec (UA);
if (match!= null) {
return {browser:match[1]¦¦ "", version:match[2]¦¦ "0"};
}
var match = rchrome.exec (UA);
if (match!= null) {
return {browser:match[1]¦¦ "", version:match[2]¦¦ "0"};
}
var match = rsafari.exec (UA);
if (match!= null) {
return {browser:match[2]¦¦ "", version:match[1]¦¦ "0"};
}
if (match!= null) {
return {browser: "", Version: "0"};
}
}
var browsermatch = Uamatch (Useragent.tolowercase ());
if (Browsermatch.browser) {
Jmeteor.browser[browsermatch.browser] = true;
Jmeteor.browsername = Browsermatch.browser;
JMeteor.browser.version = browsermatch.version;
JMeteor.browser.language = (navigator.language? navigator.language
: navigator.userlanguage¦¦ "");
}
Browser Check-----End
    
     
How to use:
JavaScript code
JMeteor.browser.msie//Determine if IE is, return true to represent
Jmeteor.browsername//Browser name
JMeteor.browser.version//Browser version
JMeteor.browser.language//language
</script>

Using browser version information to determine the browser

Copy Code code as follows:

var _uat=navigator.useragent;
if (_uat.indexof ("MSIE 6.0") >0) alert ("IE6");
else if (_uat.indexof ("MSIE 7.0") >0) alert ("IE7");
else if (_uat.indexof ("MSIE 8.0") >0) alert ("IE8");
else if (_uat.indexof ("Firefox") >0) alert ("Firefox");

CSS to judge the browser

Copy Code code as follows:

#example {color:red;}/*firefox*/
* HTML #example {color:blue;}/*ie6*/
*+html #example {Color:green}/*ie7*/

HTML Judgment Browser

Copy Code code as follows:

1. <!--[if! ie]><!--> can recognize <!--<! except IE [endif]-->
2. <!--[if ie]> all IE identifiable <! [endif]-->
3. <!--[if IE 6]> only IE6 identifiable <! [endif]-->
4.<!--[If Lt IE 6]> IE6 and IE6 The following versions can be identified <! [endif]-->
5. <!--[if GTE IE 6]> IE6 and IE6 above versions can be identified <! [endif]-->
6.<!--[If IE 7]> only IE7 identifiable <! [endif]-->
7. <!--[if Lt IE 7]> IE7 and IE7 The following versions can be identified <! [endif]-->
8. <!--[if GTE IE 7]> IE7 and IE7 above versions can be identified <! [endif]-->

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.