JavaScript learning note detection client type is (engine, browser, platform, operating system, mobile device) _ javascript skills

Source: Internet
Author: User
This article describes how to check that the client types of JavaScript learning notes are (engines, browsers, platforms, operating systems, and mobile devices). For more information, see
// Obtain the user proxy string in lowercase. Var ua = navigator. userAgent. toLowerCase (); document. write (ua );

In the previous article, we introduced the browser rendering engine, platform, Windows operating system, mobile devices, and game systems that use javascript code to detect webpage access.

If you are interested, you can click the full text to learn more.

1. Recognition and presentation Engine

The engine mainly includes four types: IE, Gecko, WebKit, and Opera

2. Identify browsers

There are four mainstream browsers: IE, Chrome, Firefox, and Opera.

3. Identification Platform

Mainstream platforms include Windows, Mac, and Unix

4. Identify Windows operating systems

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

5. Identify mobile devices

Mainstream mobile devices include iPhone, iPod, Anroid, and Nokia

6. Identify the game system.

Mainstream game systems include Wii and PS3.

Simple code differentiation found on the Internet:

JavaScript

var ua = navigator.userAgent.toLowerCase();var isStrict = document.compatMode == "CSS1Compat"isOpera = ua.indexOf("opera") > -1isChrome = ua.indexOf("chrome") > -1isSafari = !isChrome && (/webkit|khtml/).test(ua)isSafari3 = isSafari && ua.indexOf('webkit/5') != -1isIE = !isOpera && ua.indexOf("msie") > -1isIE7 = !isOpera && ua.indexOf("msie 7") > -1isIE8 = !isOpera && ua.indexOf("msie 8") > -1isGecko = !isSafari && !isChrome && ua.indexOf("gecko") > -1isGecko3 = isGecko && ua.indexOf("rv:1.9") > -1isBorderBox = isIE && !isStrict isWin7 = ua.indexOf("nt 6.1") > -1isVista = ua.indexOf("nt 6.0") > -1isWin2003 = ua.indexOf("nt 5.2") > -1isWinXp = ua.indexOf("nt 5.1") > -1isWin2000 = ua.indexOf("nt 5.0") > -1isWindows = (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);

Comprehensive code differentiation:

JavaScript

Var client = function () {// rendering engine var engine = {ie: 0, gecko: 0, webkit: 0, khtml: 0, opera: 0, // complete version: ver: null}; // browser var browser = {// main browser ie: 0, firefox: 0, konq: 0, opera: 0, chrome: 0, safari: 0, // specific version number ver: null}; // platform, device, and operating system var system = {win: false, mac: false, xll: false, // mobile device iphone: false, ipod: false, nokiaN: false, winMobile: false, macMobile: false, // game device wii: False, ps: false}; // detects the rendering engine and the 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 ["$1"]; engine. webkit = parseFloat (engine. ver); // determine whether it is Chrome or Safari if (/Chrome \/(\ S + )/. test (ua) {browser. ver = RegExp ["$1"]; browser. chrome = parseFlo At (browser. ver);} else if (/Version \/(\ S + )/. test (ua) {browser. ver = RegExp ["$1"]; browser. safari = parseFloat (browser. ver);} else {// approximately determines the version number var safariVersion = 1; if (engine. webkit <100) {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 ["$1"]; engine. khtml = browser. kong = paresFloat (engine. ver);} else if (/rv :( [^ \)] +) \) Gecko \/\ d {8 }/. test (ua) {engine. ver = RegExp ["$1"] engine. gecko = parseFloat (engine. ver); // determine if it is Firefox if (/Firefox \/(\ S + )/. test (ua) {browser. ver = RegExp ["$1"]; browser. firefox = pareseFloat (browser. ver );}} Else if (/MSIE ([^;] + )/. test (ua) {browser. ver = RegExp ["$1"]; browser. firefox = parseFloat (browser. ver);} // check the 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); // checks if (system. win) {if (/Win (?: Doms )? ([^ Do] {2}) \ s? (\ D + \. \ d + )? /. Test (ua) {if (RegExp ["$1"] = "NT") {switch (RegExp ["$2"]) {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 ["$1"]) {system. win = "ME";} else {system. win = RegExp ["$1"] ;}}// 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. wii = ua. indexOf ("Wii")>-1; system. ps =/playstation/I. test (ua); // return these objects return {engine: engine, browser: browser, system: system };}()

The above section describes all the types of JavaScript learning notes for detecting clients (engines, browsers, platforms, operating systems, and mobile devices.

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.