Jquery judges the code of IE 6 and other browsers

Source: Internet
Author: User

Jquery judges IE6 code:
Copy codeThe Code is as follows:
If ($. browser. msie & ($. browser. version = "6.0 ")&&! $. Support. style ){
// Code
}

Jquery browser Judgment Method
In jquery, the navigator. userAgent. indexOf is used to determine the browser type and perform some processing. If you do not want to use jquery, you can use it if you change the code slightly.
Jquery determines the source code of the browser (jquery1.31 is used as an example)
Js Code:
Copy codeThe Code is as follows:
Var userAgent = navigator. userAgent. toLowerCase ();
// Figure out what browser is being used
JQuery. browser = {
Version: (userAgent. match (/. + (? : Rv | it | ra | ie) [\/:] ([\ d.] +)/) | [0, '0']) [1],
Safari:/webkit/. test (userAgent ),
Opera:/opera/. test (userAgent ),
Msie:/msie/. test (userAgent )&&! /Opera/. test (userAgent ),
Mozilla:/mozilla/. test (userAgent )&&! /(Compatible | webkit)/. test (userAgent)
};

Version --- browser version
Msie ---- IE browser (Microsoft Internet Explorer)
Mozilla-Firefox
Opera-operabrowser
Js Code:
Var userAgent = navigator. userAgent. toLowerCase ();
Browser = {
Version: (userAgent. match (/. + (? : Rv | it | ra | ie) [\/:] ([\ d.] +)/) | [0, '0']) [1],
Safari:/webkit/. test (userAgent ),
Opera:/opera/. test (userAgent ),
Msie:/msie/. test (userAgent )&&! /Opera/. test (userAgent ),
Mozilla:/mozilla/. test (userAgent )&&! /(Compatible | webkit)/. test (userAgent)
}
The call is the same as that of jquery, except that the $ symbol is removed.
Reference from: http://www.zdbase.com/content/detail.aspx? OID = F50C5170-4793-4C42-966C-823D48DA5879
Jquery is used to determine the type of the browser. If this method is used only to determine the type of the browser, it is not recommended. It is only recommended when jquery is used, because there is no need to load such a large class library because of such a small function.
It is recommended that you learn about jquery and learn about it.
Main usage: $. browser. ['browser keyword ']
The Code is as follows:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function (){
If ($. browser. msie ){
$ (Function () {alert ("this is msie ");});
}
Else if ($. browser. safari)
{
$ (Function () {alert ("this is safari! ");});
}
Else if ($. browser. mozilla)
{
$ (Function () {alert ("this is mozilla! ");});
}
Else if ($. browser. opera)
{
$ (Function () {alert ("this is opera ");});
}
Else
{
$ (Function () {alert ("I don't konw! ");});
}
});
</Script>

Related Article

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.