User Agent string useragent four possible recognition

Source: Internet
Author: User

Defined

User Agent string: navigator.useragent

The HTTP specification explicitly states that the browser should send a short user-agent string that indicates the browser's name and version number. But in reality it is not so simple.

Development history

"1" 1993 U.S. NCSA National Supercomputer Center released the world's first web browser mosaic, the browser's user-agent string is mosaic/0.9

"2" Netscape Company entered the field of browser development, the code name of its own products named Mozilla (Mosaic Killer) shorthand, user-agent string format for the mozilla/version number [language] (platform; encryption type)

"3" IE released the first to win the user's widely recognized web browser IE3, at that time Netscap has occupied an absolute market share, in order to allow the server to detect Ie,ie to modify the user agent string into a compatible form of Netscape: mozilla/2.0 ( Compatible MSIE version number; operating system)

"4" browsers appear successively, the user agent string display format is more and more similar ...

Test tools

Using the various desktop browser debugging tools, mainly IE debugging tools and Chrome's emulation phone debugging tools

Desktop-side test results

"1" IE
[1.1] IE3
mozilla/2.0 (compatible; MSIE3.02; Windows 95)
[1.2] IE6
mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
[1.3] IE7
mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
[1.4] IE8
mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; trident/4.0)
[1.5] IE9
mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; trident/5.0)
[1.6] IE10
mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; trident/6.0)
[1.7] IE11
mozilla/5.0 (MSIE 9.0; Windows NT 6.1; WOW64; trident/7.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729;. net4.0c;. net4.0e; infopath.3; gwx:qualified; rv:11.0) Like Gecko


"2" Chrome
mozilla/5.0 (Windows NT 6.1; WOW64) G applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.93 safari/537.36


"3" Safari
mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/534.57.2 (khtml, like Gecko) version/5.1.7 safari/534.57.2


"4" Firefox
mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) gecko/20100101 firefox/40.0


"5" Opera
mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.85 safari/537.36 opr/32.0.1948.25

Mobile End Test Results

"1" ipad
mozilla/5.0 (IPad; CPU os 7_0 like Mac os X applewebkit/537.51.1 (khtml, like Gecko) version/7.0 mobile/11a465 safari/9537.53


"2" iphone
mozilla/5.0 (IPhone; CPU iPhone os 8_0 like Mac os X applewebkit/600.1.3 (khtml, like Gecko) version/8.0 mobile/12a4345d safari/600.1.4


"3" Android
mozilla/5.0 (Linux; Android 4.2.2; gt-i9505 build/jdq39) applewebkit/537.36 (khtml, like Gecko) chrome/31.0.1650.59 Mobile safari/537.36

Identify the browser kernel

Common kernels are Trident, Gecko, and WebKit
[note] because the word like gecko may appear in the user agent string for Trident and WebKit, the final test is Gecko

functionWhichengine () {varUA =navigator.useragent; //Trident Kernel    if(/trident/. Test (UA)) {        return"Trident"; }    //WebKit Kernel    if(/webkit/. Test (UA)) {        return"WebKit"; }            //Gecko Kernel    if(/gecko/. Test (UA)) {        return"Gecko"; }}console.log (Whichengine ());//IE11 Display "Trident"

Identify browser version

"1" IE

Ie3-ie10 can be judged by the version number of the MSIE, because some IE11 do not appear msie characters, and there are RV fields in Safari, so IE11 need to use the RV version number and Trident to match the judgment

functionIsie () {varUA =navigator.useragent; //Detection Trident engine, ie8+    if(/trident/. Test (UA)) {        //ie11+        if(/RV: (\d+)/. Test (UA)) {            returnregexp["$"]; }            //Ie8-ie10        if(/msie (\d+)/. Test (UA)) {            returnregexp["$"]; }            }    //detect IE logo, ie7-    if(/msie (\d+)/. Test (UA)) {        returnregexp["$"]; }}console.log (Isie ());//only IE returns the version number, and the other browsers return undefined

"2" Chrome

function Ischrome () {    var ua = navigator.useragent;     // Get rid of opera first, because opera only adds its own logo    after Chrome's useragent. if (!/opr/. Test (UA)) {        if(/chrome\/(\s+)/. Test (UA)) {            return regexp["$"];}}    } Console.log (Ischrome ()); // only Chrome returns version number 45.0.2454.93, and other browsers return undefined

"3" Safari

functionIssafari () {varUA =navigator.useragent; //First rule out opera .    if(!/opr/. Test (UA)) {        //check out Chrome and Safari browser        if(/safari/. Test (UA)) {            //Detect Safari            if(/version\/(\s+)/. Test (UA)) {                returnregexp["$"]; }}}}console.log (Issafari ());//only Safari returns version number 5.1.7, and other browsers return undefined

"4" Firefox

function Isfirefox () {    if(/firefox\/(\s+)/. Test (navigator.useragent)) {        return regexp["$"];    }    } Console.log (Isfirefox ()); // only Firefox will return version number 40.0, other browsers will return undefined

"5" Opera

function Isopera () {    if(/opr\/(\s+)/. Test (navigator.useragent)) {        return regexp["$"];    }    } Console.log (Isopera ()); // only opera will return version number 32.0.1948.25, and other browsers will return    undefined

Identify the operating system

Using Navigator.platform to detect the operating system is simpler because it may include values such as "Win32", "Win64", "MACPPC", "Macintel", "X11", "Linux i686" and so on, and is consistent across browsers.
The details of the window system have been obtained through navigator.useragent.

Windows                                     XP                        -             5.1 windowsVista                     -             6.0 with kernel version 7                         ,             6.18                         ,             6.28.1                       ,             6.3Windows 10 Technical Preview                          -6.4(Build 9880+)                        

functionWhichsystem () {varUA =navigator.useragent; varPF =Navigator.platform; if(/mac/. Test (PF)) {        return"Mac"; }    if(/x11/.test (PF) | |/linux/. Test (PF)) {        return"Linux"; }    if(/win/. Test (PF)) {        if(/windows NT (\d+\.\d+)/. Test (UA)) {            Switch(regexp["$"]){                 Case"5.0":                    return"Windows 2000";  Case"5.1":                    return"Windows XP";  Case"6.0":                    return"Windows Vista";  Case"6.1":                    return"Windows 7";  Case"6.2":                    return"Windows 8";  Case"6.3":                    return"Windows 8.1";  Case"6.4":                 Case"10":                    return"Windows 10"; }}}}console.log (Whichsystem ())//Windows 7

Identify mobile devices
functionWhichmobile () {varUA =navigator.useragent; if(/iphone OS (\d+_\d+)/. Test (UA)) {        return' IPhone Mac ' + regexp.$1.replace ("_", ".")); }    if(/ipad.+os (\d+_\d+)/. Test (UA)) {        return' IPad Mac ' + regexp.$1.replace ("_", "."))    }    if(/android (\d+\.\d+)/. Test (UA)) {        return' Android ' + regexp[' $ ']; }}console.log (Whichmobile ())//Android 5.1

User Agent string useragent four possible recognition

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.