search
HomeWeb Front-endJS TutorialDetect browser rendering engines, platforms, Windows operating systems, mobile devices and game systems that access web pages based on javascript code_javascript skills

废话不多说了,直接给大家贴js代码了,代码附有注释,感兴趣的朋友一起学习吧。

/**
 * Author: laixiangran.
 * Created by laixiangran on 2015/12/02.
 * 检测访问网页的浏览器呈现引擎、平台、Windows操作系统、移动设备和游戏系统
 * ********************************************************************
 * 各版本浏览器在windows10.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 = {};
 //呈现引擎信息
 var engine = {
 //呈现引擎
 ie: 0,
 gecko: 0,
 webkit: 0,
 khtml: 0,
 opera:0,
 //具体版本号
 ver: null
 };
 var browser = {
 //浏览器
 ie: 0,
 edge: 0,
 firefox: 0,
 safari: 0,
 konq: 0,
 opera: 0,
 chrome: 0,
 //具体版本号
 ver: null
 };
 //平台、设备和操作系统
 var system = {
 win: false,
 mac: false,
 unix: false,
 //移动设备
 iphone: false,
 ipod: false,
 ipad: false,
 ios: false,
 android: false,
 nokiaN: false,
 winMobile: false,
 //游戏系统
 wii: false, //任天堂
 ps: false //Playstation3
 };
 //获取浏览器的用户代理字符串
 var ua = window.navigator.userAgent;
 //检测呈现引擎和浏览器
 //检测Presto内核的Opera浏览器
 if(window.opera){
 engine.ver = browser.ver = window.opera.version();
 engine.opera = browser.opera = parseFloat(engine.ver);
 }
 //检测WebKit 用代理字符串中的"AppleWebKit"进行检测
 else if(/AppleWebKit\/(\S+)/.test(ua)){
 engine.ver = RegExp["$1"];
 engine.webkit = parseFloat(engine.ver);
 //确定Microsoft Edge
 if(/Edge\/(\S+)/.test(ua)){
  browser.ver = RegExp["$1"];
  browser.edge = parseFloat(browser.ver);
 }
 //确定WebKit内核Opera
 else if(/OPR\/(\S+)/.test(ua)){
  browser.ver = RegExp["$1"];
  browser.opera = parseFloat(browser.ver);
 }
 //确定Chrome
 else if(/Chrome\/(\S+)/.test(ua)){
  browser.ver = RegExp["$1"];
  browser.chrome = parseFloat(browser.ver);
 }
 //确定Safari
 else if(/Version\/(\S+)/.test(ua)){
  browser.ver = RegExp["$1"];
  browser.safari = parseFloat(browser.ver);
 }else{
  //近似的确定版本号
  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;
 }
 }
 //检测KHTML 用于Konqueror3.1及更早版本中不包含KHTML的版本,故而就要使用Konqueror的版本来代替
 else if(/KHTML\/(\S+)/.test(ua) || /Konqueror\/(\S+)/.test(ua)){
 engine.ver = browser.ver = RegExp["$1"];
 engine.khtml = browser.konq = parseFloat(engine.ver);s
 }
 //检测Gecko 其版本号在字符串"rv:"的后面
 else if(/rv:([^\)]+)\) Gecko\/\d{8}/.test(ua)){
 engine.ver = RegExp["$1"];
 engine.gecko = parseFloat(engine.ver);
 //确定Firefox
 if(/Firefox\/(\S+)/.test(ua)){
  browser.ver = RegExp["$1"];
  browser.firefox = parseFloat(browser.ver);
 }
 }
 //检测IE
 else if(/MSIE ([^;]+)/.test(ua) || /rv:([^\)]+)\) like Gecko/.test(ua)){
 engine.ver = browser.ver = RegExp["$1"];
 engine.ie = browser.ie = parseFloat(engine.ver);
 }
 //获取平台或者操作系统信息,可能的值:win32、win64、MacPPC、MacIntel、Xll、Linux i686
 var p = window.navigator.platform;
 //检测平台
 system.win = p.indexOf("Win") == 0;
 system.mac = p.indexOf("Mac") == 0;
 system.unix = (p == "Xll'") || (p.indexOf("Linux") == 0);
 //检测Windows操作系统
 if(system.win){
 if(/Win(&#63;:dows )&#63;([^do]{2})\s&#63;(\d+\.\d+)&#63;/.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;
   case "7":
   system.win = "7";
   break;
   case "8":
   system.win = "8";
   break;
   case "8.1":
   system.win = "8.1";
   break;
   case "10.0":
   system.win = "10.0";
   break;
   default:
   system.win = "NT";
   break;
  }
  }
 }
 }
 //移动设备
 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 = system.win;
 }else if(system.win == "Ph"){
 if(/Windows Phone OS (\d+.\d+)/.test(ua)){
  system.win = "Phone";
  system.winMobile = parseFloat(RegExp["$1"]);
 }
 }
 //检测iOS版本
 if(system.mac && ua.indexOf("Mobile") > -1){
 if(/CPU (&#63;:iPhone )&#63;OS (\d+.\d+)/.test(ua)){
  system.ios = parseFloat(RegExp["$1"].replace("_","."));
 }else{
  system.ios = 2; //不能真正检测出来,所以只能猜测
 }
 }
 //检测安卓版本
 if(/Android (\d+.\d+)/.test(ua)){
 system.android = parseFloat(RegExp["$1"]);
 }
 //检测游戏系统
 system.wii = ua.indexOf("wii") > -1;
 system.ps = /playstation/i.test(ua);
 window.iClient.engine = engine;
 window.iClient.browser = browser;
 window.iClient.system = system;
})(); 

以上内容是小编给大家分享的基于javascript实现检测访问网页的浏览器呈现引擎、平台、Windows操作系统、移动设备和游戏系统的全部叙述,希望大家喜欢。下面文章给大家介绍JavaScript学习笔记之检测客户端类型是(引擎、浏览器、平台、操作系统、移动设备),敬请关注。!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Replace String Characters in JavaScriptReplace String Characters in JavaScriptMar 11, 2025 am 12:07 AM

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

jQuery Check if Date is ValidjQuery Check if Date is ValidMar 01, 2025 am 08:51 AM

Simple JavaScript functions are used to check if a date is valid. function isValidDate(s) { var bits = s.split('/'); var d = new Date(bits[2] '/' bits[1] '/' bits[0]); return !!(d && (d.getMonth() 1) == bits[1] && d.getDate() == Number(bits[0])); } //test var

jQuery get element padding/marginjQuery get element padding/marginMar 01, 2025 am 08:53 AM

This article discusses how to use jQuery to obtain and set the inner margin and margin values ​​of DOM elements, especially the specific locations of the outer margin and inner margins of the element. While it is possible to set the inner and outer margins of an element using CSS, getting accurate values ​​can be tricky. // set up $("div.header").css("margin","10px"); $("div.header").css("padding","10px"); You might think this code is

10 jQuery Accordions Tabs10 jQuery Accordions TabsMar 01, 2025 am 01:34 AM

This article explores ten exceptional jQuery tabs and accordions. The key difference between tabs and accordions lies in how their content panels are displayed and hidden. Let's delve into these ten examples. Related articles: 10 jQuery Tab Plugins

10 Worth Checking Out jQuery Plugins10 Worth Checking Out jQuery PluginsMar 01, 2025 am 01:29 AM

Discover ten exceptional jQuery plugins to elevate your website's dynamism and visual appeal! This curated collection offers diverse functionalities, from image animation to interactive galleries. Let's explore these powerful tools: Related Posts: 1

HTTP Debugging with Node and http-consoleHTTP Debugging with Node and http-consoleMar 01, 2025 am 01:37 AM

http-console is a Node module that gives you a command-line interface for executing HTTP commands. It’s great for debugging and seeing exactly what is going on with your HTTP requests, regardless of whether they’re made against a web server, web serv

Custom Google Search API Setup TutorialCustom Google Search API Setup TutorialMar 04, 2025 am 01:06 AM

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

jquery add scrollbar to divjquery add scrollbar to divMar 01, 2025 am 01:30 AM

The following jQuery code snippet can be used to add scrollbars when the div content exceeds the container element area. (No demonstration, please copy it directly to Firebug) //D = document //W = window //$ = jQuery var contentArea = $(this), wintop = contentArea.scrollTop(), docheight = $(D).height(), winheight = $(W).height(), divheight = $('#c

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor