Check the browser version information or browsers. We can determine the user's user-agent features. Next, I will only introduce the inspection of four mainstream browsers. other browsers can be automatically added.
Let's take a look at the user-agent of the following four mainstream browsers:
Safari (Windows edition)
... AppleWebKit/523.12.9 (KHTML, like Gecko) Version/3.0 Safari/523.12.9
Opera (Opera 9.2 on Windows XP)
Opera/9.24 (Windows NT 5.1; U; zh-cn)
Mozilla (Firefox 2.0.11 on Windows XP)
... Windows NT 5.1; zh-CN; rv: 1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Internet Explorer (7.0 on Windows XP)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Core code
The Code is as follows: |
Copy code |
Var userAgent = navigator. userAgent. toLowerCase (); // Figure out what browser is being used JQuery. browser = { Version: (userAgent. match (/. + (? : Rv | it | ra | ie) [/:] ([d.] +)/) | []) [1], Safari:/webkit/. test (userAgent ), Opera:/opera/. test (userAgent ), Msie:/msie/. test (userAgent )&&! /Opera/. test (userAgent ), Mozilla:/mozilla/. test (userAgent )&&! /(Compatible | webkit)/. test (userAgent) }; |
In this way, you can quickly obtain information about the browser by using the $. browser object attributes in jQuery. $. Browser object: jQuery. browser object
Example of viewing browser-related information
The Code is as follows: |
Copy code |
<Div id = "tip"> </div> <Script> $ (Function (){ Var browserTip = "your browser name is :"; If ($. browser. msie) {// IE browser BrowserTip + = "IE "; } If ($. browser. mozilla) {// Firefox BrowserTip + = "Mozilla Firefox "; } BrowserTip + = "version:" + $. browser. version; // obtain the version number. $ ("# Tip" ).html (browserTip ); }) </Script> |