Javascript browser Detection

Source: Internet
Author: User

Javascript browser Detection

Browser kernel:

The core part of a browser is called the "Rendering Engine", also known as the "Rendering Engine", which is usually called the browser kernel.

The browser kernel determines how the browser displays the content and format of the webpage.

Kernel category:

1. Trident (IE kernel): IE 6/IE7/IE8 (Trident 4.0). IE9 (Trident 5.0). IE10 (Trident 10.0) is used in IE kernel browsers ). Of course, many browsers in China use the IE kernel, but they are not IE browsers (shell browsers ). For example: 360 security browser (1.0-5.0 using Trident), 6.0 using Trident + WebKit, 7.0 using Trident + Blink, Cheetah browser, ghost browser, and sogou high-speed browser.

Many browsers are now called "dual-core" or "multi-core". One of them uses Trident, and another kernel is added, which is called "high-speed browser mode" in China ". Trident is used for compatibility mode.

2. Gekco (Firefox kernel): Firefox browser.

3. Presto (an earlier version of Opera): It is now obsolete.

4. Webkit (Safari kernel, Chrome kernel): Apple's kernel is also Apple's Safari kernel, this kernel is used in Chrome, Safari, 360 and sogou browsers in high-speed mode.

5. Blink: it is a browser typographical engine developed by Google and Opera software. It is used after Chrome 28 and Opera 15.

Typographical engine:

1. Webcore: developed by Apple, the main web browser that uses Webcore is Safari.

2. KHTML.

Javascript to obtain client information:

Navigator contains information about the browser.

Object Attributes (list several common attributes ):

1. appVersion: return the platform and version information of the browser.

2. platform: return the name of the operating platform that runs the browser.

3. userAgent: return the user-agent header value sent by the client to the server.

Display of userAgent in various browsers:

Firefox: gecko uses the kernel, followed by version 20100101. You can also use firefox to determine whether the firefox browser is installed with version 35.0.


Opera: different versions may have different results: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20150129/20150129085139147.png" alt = "\">

IE9.0: You can use msie to determine whether the browser is an Internet Explorer.


Chrome:


Safari:


Imperfect browser support in China:

 Untitled document<Script type = "text/javascript">/*** obtain the browser type and Version Number *. Domestic browsers are supported: cheetah browser, sogou browser, ao travel browser, 360 speed browser, 360 security browser, * QQ browser, Baidu browser, etc. * supports foreign browsers such as IE, Firefox, Chrome, safari, and Opera. * usage: * obtain the Browser version: Browser. client. version * Get the Browser name (Shell): Browser. client. name * @ author: xuzengqiang * @ since: 10:26:11 **/var Browser = Browser | (function (window) {var document = w.w.doc ument, navigator = window. navigator, agent = navigato R. userAgent. toLowerCase (), // IE8 + supported. return the mode used by the browser to render the current document // IE6, IE7: undefined. IE8: 8 (compatible mode returns 7 ). IE9: 9 (compatible mode returns 7 | 8) // IE10: 10 (compatible mode 7 | 8 | 9) IEMode = document.doc umentMode, // chormechrome = window. chrome | false, System = {// user-agentagent: agent, // whether it is IEisIE:/msie /. test (agent), // Gecko kernel isGecko: agent. indexOf ("gecko")> 0 & agent. indexOf ("like gecko") <0, // webkit kernel isWebkit: agent. indexOf ("webkit")> 0, // whether the isSt is in the standard mode Rict: document. compatMode = "CSS1Compat", // whether subtitlesupportSubTitle: function () {return "track" in document. createElement ("track") ;}, // whether scopedsupportScope: function () {return "scoped" in document. createElement ("style") ;}, // obtain the IE version number ieVersion: function () {try {return agent. match (/msie ([\ d.] +)/) [1] | 0;} catch (e) {console. log ("error"); return IEMode ;}}, // Opera version operaVersion: function () {try {if (Window. opera) {return agent. match (/opera. ([\ d.] +)/) [1];} else if (agent. indexOf ("opr")> 0) {return agent. match (/opr \/([\ d.] +)/) [1] ;}} catch (e) {console. log ("error"); return 0 ;}, // Description: version filtering. for example, 31.0.252.152 only retains 31.0 versionFilter: function () {if (arguments. length = 1 & typeof arguments [0] = "string") {var version = arguments [0]; start = version. indexOf (". "); if (start> 0) {end = version. indexOf (". ", star T + 1); if (end! =-1) {return version. substr (0, end) ;}} return version;} else if (arguments. length = 1) {return arguments [0];} return 0 ;}}; try {// browser type (IE, Opera, Chrome, Safari, Firefox) System. type = System. isIE? "IE": window. opera | (agent. indexOf ("opr")> 0 )? "Opera": (agent. indexOf ("chrome")> 0 )? "Chrome": // safari also provides a special Judgment Method window. openDatabase? "Safari" :( agent. indexOf ("firefox")> 0 )? "Firefox": 'unknow'; // version number System. version = (System. type = "IE ")? System. ieVersion () :( System. type = "Firefox ")? Agent. match (/firefox \/([\ d.] +)/) [1] :( System. type = "Chrome ")? Agent. match (/chrome \/([\ d.] +)/) [1] :( System. type = "Opera ")? System. operaVersion () :( System. type = "Safari ")? Agent. match (/version \/([\ d.] +)/) [1]: "0"; // browser shell System. shell = function () {// if (agent. indexOf ("maxthon")> 0) {System. version = agent. match (/maxthon \/([\ d.] +)/) [1] | System. version; return "Proud Browser";} // QQ browser if (agent. indexOf ("qqbrowser")> 0) {System. version = agent. match (/qqbrowser \/([\ d.] +)/) [1] | System. version; return "QQ Browser";} // if (agent. indexOf ("se 2.x")> 0) {return 'sogou browser';} // Chrome: Use window. chrome & window. chrome. webstore to determine if (chrome & System. type! = "Opera") {var external = window. external, clientInfo = window. clientInformation, // The client language: zh-cn, zh.360 will return undefinedclientLanguage = clientInfo. ages; // cheetah Browser: or agent. indexOf ("lbbroversion")> 0if (external & 'liebaogetversion' in external) {return 'cheetah browser';} // Baidu browser if (agent. indexOf ("bidubrowser")> 0) {System. version = agent. match (/bidubrowser \/([\ d.] +)/) [1] | agent. match (/chrome \/([\ d.] +)/) [1]; retu Rn "Baidu Browser";} // 360 speed browser and 360 security browser if (System. supportSubTitle () & typeof clientLanguage = "undefined") {// object. key () returns an array. contains the enumerated property and method name var storeKeyLen = Object. keys (chrome. webstore ). length, v8Locale = "v8Locale" in window; return storeKeyLen> 1? '1970 speedy browsers ': '1970 secure browsers';} return "Chrome";} return System. type ;}; // browser name (if it is a shell browser, return the Shell Name) System. name = System. shell (); // filter the version number and process the System. version = System. versionFilter (System. version);} catch (e) {console. log ("error") ;}return {client: System };} (window); alert (Browser. client. name + "" + Browser. client. version); </script>






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.