Browser rendering engine, platform, Windows operating system, mobile device and game system _javascript techniques based on JavaScript code detection access to Web pages

Source: Internet
Author: User
Tags microsoft edge


Nonsense do not say much, directly to everyone paste JS code, code with comments, interested friends to study together.


* *
* Author: laixiangran.
* Created by laixiangran on 2015/12/02.
*Detect browser rendering engine, platform, windows operating system, mobile device and game system accessing web page
* ********************************************************************
*The user agent string of each version of browser under Windows 10.0:
* Google Chrome 45.0.2454.85 —— "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"
* Opera 31.0.1889.174 —— "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174"
* Microsoft Edge —— "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"
* Firefox 40.0.3 —— "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0"
* Internet Explorer 11+ —— "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko"
* Internet Explorer 10- —— "Mozilla/5.0 (compatible; MSIE x.0; Windows NT 10.0; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)"
* /
(function () {
window.iClient = {};
//Rendering engine information
var engine = {
//Rendering engine
Ie: 0,
Gecko: 0,
Webkit: 0,
Khtml: 0,
Opera:0,
//Specific version No
Ver: null
}
var browser = {
/ / browser
Ie: 0,
Edge: 0,
Firefox: 0,
Safari: 0,
Konq: 0,
Opera: 0,
Chrome: 0,
//Specific version No
Ver: null
}
//Platforms, devices and operating systems
var system = {
Win: false,
Mac: false,
Unix: false,
//Mobile devices
iphone: false,
Ipod: false,
Ipad: false,
Ios: false,
android: false,
nokiaN: false,
winMobile: false,
//Game system
Wii: false, / / Nintendo
ps: false //Playstation3
}
//Get the browser's user agent string
var ua = window.navigator.userAgent;
//Detect rendering engine and browser
//Opera browser to detect Presto kernel
if(window.opera){
engine.ver = browser.ver = window.opera.version();
engine.opera = browser.opera = parseFloat(engine.ver);
}
//Detect WebKit using "applewebkit" in the proxy string
else if(/AppleWebKit\/(\S+)/.test(ua)){
engine.ver = RegExp["$1"];
engine.webkit = parseFloat(engine.ver);
//Identify Microsoft edge
if(/Edge\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.edge = parseFloat(browser.ver);
}
//Determine WebKit kernel Opera
else if(/OPR\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.opera = parseFloat(browser.ver);
}
//Confirm Chrome
else if(/Chrome\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.chrome = parseFloat(browser.ver);
}
//Identify Safari
else if(/Version\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.safari = parseFloat(browser.ver);
}else{
//Approximate definitive 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.ver = browser.safari = safariVersion;
}
}
//Detection of KHTML is used for versions of Konqueror 3.1 and earlier that do not contain KHTML. Therefore, Konqueror's version should be used instead
else if(/KHTML\/(\S+)/.test(ua) || /Konqueror\/(\S+)/.test(ua)){
engine.ver = browser.ver = RegExp["$1"];
engine.khtml = browser.konq = parseFloat(engine.ver);s
}
//Detect gecko whose version number follows the string "RV:"
else if(/rv:([^\)]+)\) Gecko\/\d{8}/.test(ua)){
engine.ver = RegExp["$1"];
engine.gecko = parseFloat(engine.ver);
//Determine Firefox
if(/Firefox\/(\S+)/.test(ua)){
browser.ver = RegExp["$1"];
browser.firefox = parseFloat(browser.ver);
}
}
/ / detect IE
else if(/MSIE ([^;]+)/.test(ua) || /rv:([^\)]+)\) like Gecko/.test(ua)){
engine.ver = browser.ver = RegExp["$1"];
engine.ie = browser.ie = parseFloat(engine.ver);
}
//Get platform or operating system information, possible values: Win32, win64, macppc, macintel, XLL, Linux i686
var p = window.navigator.platform;
//Detection platform
system.win = p.indexOf("Win") == 0;
system.mac = p.indexOf("Mac") == 0;
system.unix = (p == "Xll'") || (p.indexOf("Linux") == 0);
//Detect windows operating system
if(system.win){
if(/Win(?:dows )?([^do]{2})\s?(\d+\.\d+)?/.test(ua)){
if(RegExp["$1"] == "NT"){
switch(RegExp["$2"]){
Case "5":
system.win = "2000";
Break;
Case "5.1":
system.win = "XP";
Break;
Case "6":
system.win = "Vista";
Break;
Case "7":
system.win = "7";
Break;
Case "8":
system.win = "8";
Break;
Case "8.1":
system.win = "8.1";
Break;
Case "10":
system.win = "10.0";
Break;
Default:
system.win = "NT";
Break;
}
}
}
}
//Mobile devices
system.iphone = ua.indexOf("iPhone") > -1;
system.ipod = ua.indexOf("iPod") > -1;
system.ipad = ua.indexOf("iPad") > -1;
system.nokiaN = ua.indexOf("NokiaN") > -1;
//window mobile
if(system.win == "CE"){
system.winMobile = 


The above content is a small compilation for you to share the browser to detect access to the Web page rendering engine, platform, Windows operating system, mobile devices and game system, all the description, I hope you like. The following article to introduce the JavaScript learning notes of the detection client type is (engine, browser, platform, operating system, mobile device), please pay attention to.


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.