JavaScript Learning notes the detection client type is (engine, browser, platform, operating system, mobile device) _javascript tips

Source: Internet
Author: User
Gets the user agent string and all lowercase.
var ua = Navigator.userAgent.toLowerCase ();
document.write (UA);

In the previous article, we introduced the browser rendering engine, platform, Windows operating system, mobile device and game system based on JavaScript code detection Access Web page

, interested friends can click the full text to learn more details.

1. Identify the rendering engine

The main engine contains four kinds: IE, Gecko, WebKit, Opera

2, identify the browser

Mainstream browser contains four kinds: IE, Chrome, Firefox, Opera

3. Recognition platform

The mainstream platform includes three categories: Windows, Mac, Unix

4. Identify Windows operating system

Windows 98, Window NT, Window XP, Window Vista, Windows 7 ...

5. Identify mobile devices

Mainstream mobile devices include three categories: IPhone, IPod, Anroid, Nokia

6, identify the game system.

The mainstream game system includes two kinds: Wii, PS3.

On-line discovery of a relatively simple code of Distinction:

Javascript

var ua = Navigator.userAgent.toLowerCase (); var isstrict = Document.compatmode = = "Css1compat" Isopera = Ua.indexof ("opera") >-1 ischrome = Ua.indexof ("Chrome") & Gt
-1 Issafari =!ischrome && (/webkit|khtml/). Test (UA) IsSafari3 = Issafari && ua.indexof (' WEBKIT/5 ')!=-1 Isie =!isopera && ua.indexof ("MSIE") >-1 isIE7 =!isopera && ua.indexof ("MSIE 7") >-1 isIE8 =!is  Opera && ua.indexof ("MSIE 8") >-1 Isgecko =!issafari &&!ischrome && ua.indexof ("Gecko") > -1 IsGecko3 = Isgecko && ua.indexof ("rv:1.9") >-1 isborderbox = Isie &&!isstrict isWin7 = Ua.indexo F ("NT 6.1") >-1 Isvista = Ua.indexof ("NT 6.0") >-1 isWin2003 = Ua.indexof ("NT 5.2") >-1 ISWINXP = Ua.indexof (" NT 5.1 ") > 1 isWin2000 = Ua.indexof (" NT 5.0 ") >-1 iswindows = (Ua.indexof (" Windows ")!=-1 | | ua.indexof (" Win32 ") !=-1) Ismac = (ua.indexof ("Macintosh")!=-1 | | ua.indexof ("Mac OS X")!=-1) Isair = (Ua.indexoF ("Adobeair")!=-1) Islinux = (Ua.indexof ("Linux")!=-1) var sys = ""; 
var broser = ""; if (Isie) {broser = "IE 6";} else if (isIE7) {broser = "IE 7";} else if (isIE8) {broser = "IE 8";} else if (isopera) {broser = "Opera";} else if (ischrome) {broser = "Chrome";} else if (Issafari) {broser = "Safari";} else if (isSafari3) {broser = "Safari3";} 
else{broser = "Unknow";} if (isWin7) {sys = "Windows 7";} else if (isvista) {sys = "Vista";} else if (ISWINXP) {sys = "Windows XP";} else if (isWin2003) {sys = "Windows 2003";} else if (isWin2000) {sys = "Windows 2000";} else if (iswindows) {sys = "Windows";} else if (ISMAC) {sys = "Macintosh";} else if (isair) {sys = ' adobeair ';} else if (islinux) {sys = "Linux";}
else{sys = "Unknow";} document.write (UA); Alert (sys + ":" + broser);

More comprehensive Code of Distinction:

Javascript

var client = function () {//render engine var engine = {ie:0, gecko:0, webkit:0, khtml:0, opera:0,//full version number ver
: null};   Browser var browser = {//main browser ie:0, firefox:0, konq:0, opera:0, chrome:0, safari:0,//Specific version number ver
: null};  platforms, devices and operating systems VAR system ={Win:false, Mac:false, Xll:false,//Mobile devices Iphone:false, Ipod:false, Nokian:
False, Winmobile:false, Macmobile:false,//Game device Wii:false, ps:false};
Detection rendering engine and browser var ua = navigator.useragent;
 if (window.opera) {engine.ver = Browser.ver = Window.opera.version ();
Engine.opera = Browser.opera = parsefloat (engine.ver);
 else if (/applewebkit\/(\s+)/.test (UA)) {Engine.ver = regexp["$"];
 Engine.webkit = parsefloat (engine.ver);
 Determine if Chrome or Safari if (/chrome\/(\s+)/.test (UA)) {Browser.ver = regexp["$"];
 Browser.chrome = parsefloat (browser.ver);
 else if (/version\/(\s+)/.test (UA)) {Browser.ver = regexp["$"];
 Browser.safari = parsefloat (browser.ver); } else {//Approximately determine the version number var safariversion = 1;
 if (Engine.webkit < MB) {safariversion = 1;
 else if (Engine.webkit < 312) {safariversion = 1.2;
 else if (Engine.webkit < 412) {safariversion = 1.3;
 else {safariversion = 2; 
 } Browser.safari = Browser.ver = safariversion; } else if (/khtml\/(\s+)/.test (UA) | |/konquersor\/([^;]
 +)/.test (UA)) {engine.ver = Browser.ver = regexp["$"]; 
engine.khtml = Browser.kong = Paresfloat (engine.ver);
 else if (/rv: ([^\)]+) \ gecko\/\d{8}/.test (UA)) {Engine.ver = regexp["$"] Engine.gecko = parsefloat (engine.ver);
 Determine if the Firefox if (/firefox\/(\s+)/.test (UA)) {Browser.ver = regexp["$"];
 Browser.firefox = Paresefloat (browser.ver); } else if (/msie ([^;]
 +)/.test (UA)) {Browser.ver = regexp["$"];
Browser.firefox = parsefloat (browser.ver);
}//Detect browser browser.ie = engine.ie;
Browser.opera = Engine.opera;
Detection platform var p = navigator.platform;
System.win = P.indexof ("win") = = 0;
System.mac = P.indexof ("mac") = = 0; system.x11 = (p = = "X11") | |
(P.indexof ("Linux") = = 0); Detects the Windows operating system if (System.win) {if (/win) {if (?:d OMS)? ( [^do] {2}) \s?
   (\d+\.\d+)/.test (UA)) {if (regexp["$" = = "NT") {switch (regexp["$"]) {case "5.0": System.win = "2000";
  Break
   Case "5.1": System.win = "XP";
  Break
   Case "6.0": System.win = "Vista";
  Break
   Default:system.win = "NT";  
  Break
 else if (regexp["$") {System.win = "ME";
 else {System.win = regexp["$"];
}}//mobile device System.iphone = Ua.indexof ("iphone") >-1;
System.ipod = Ua.indexof ("ipod") >-1;
System.nokian = Ua.indexof ("Nokian") >-1;
System.winmobile = (System.win = = "CE");
System.macmobile = (System.iphone | | system.ipod);
Game system system.wii = Ua.indexof ("Wii") >-1;
system.ps =/playstation/i.test (UA);
Returns these objects return {engine:engine, browser:browser, System:system}; }()

The above is a small set to introduce the JavaScript learning notes of the detection client type is (engine, browser, platform, operating system, mobile device) All the description, I hope you like.

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.