JS 获取当前操作系统类型,浏览器,终端类型的工具
2021-07-12 08:06
标签:ipa int dev dap dos ant offset ie7 ret 总结了一个JavaScript获取当前终端类型(pc, mobile),操作系统类型,浏览器类型,浏览器版本的小工具。 个人觉得还行,测试过没有问题,能识别ie7以及以上。 JS 获取当前操作系统类型,浏览器,终端类型的工具 标签:ipa int dev dap dos ant offset ie7 ret 原文地址:http://www.cnblogs.com/weihuan098/p/7082688.html/**
author: Weihuan
date: 2017-6-26
**/
var _AgentInfo = {
deviceType: "", // pc or mobile
OSname: "", // windows, Android, linux and so on...
browserName: "", // chrome, safari, firefox, IE and so on...
browserVer: "", // browser version, important if in IE environment.
adaptType: 0, // A type value, Adapt to the screen due to width
_init: function(){
_AgentInfo.setDeviceAndOS();
_AgentInfo.setBrowser();
},
setDeviceAndOS: function(){
var name = "unknown";
if(window.navigator.userAgent.indexOf("Android") != -1){
name = "Android";
}else if(window.navigator.userAgent.indexOf("iPhone") != -1){
name = "iPhone";
}else if(window.navigator.userAgent.indexOf("SymbianOS") != -1){
name = "SymbianOS";
}else if(window.navigator.userAgent.indexOf("Windows Phone") != -1){
name = "Windows Phone";
}else if(window.navigator.userAgent.indexOf("iPad") != -1){
name = "iPad";
}else if(window.navigator.userAgent.indexOf("iPod") != -1){
name = "iPod";
}
if(name != "unknown"){
_AgentInfo.OSname = name;
_AgentInfo.deviceType = "mobile";
return;
}
if (window.navigator.userAgent.indexOf("Windows NT 10.0")!= -1){
name="Windows 10";
}else if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1){
name="Windows 8";
}else if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1){
name="Windows 7";
}else if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1){
name="Windows Vista";
}else if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1){
name="Windows XP";
}else if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1){
name="Windows 2000";
}else if (window.navigator.userAgent.indexOf("Mac") != -1){
name="Mac/iOS";
}else if (window.navigator.userAgent.indexOf("X11") != -1){
name="UNIX";
}else if (window.navigator.userAgent.indexOf("Linux") != -1){
name="Linux";
}
_AgentInfo.OSname = name;
_AgentInfo.deviceType = "pc";
},
setBrowser: function(){
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var fullVersion = ‘‘+parseFloat(navigator.appVersion);
var majorVersion = parseInt(navigator.appVersion,10);
var nameOffset,verOffset,ix;
if ((verOffset=nAgt.indexOf("Opera"))!=-1) { // In Opera, the true version is after "Opera" or after "Version"
browserName = "Opera";
fullVersion = nAgt.substring(verOffset+6);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
else if ( (nAgt.indexOf("Trident"))!=-1 ) { // ( ver >= ie7) In MSIE, the true version is after "MSIE" in userAgent
if((verOffset=nAgt.indexOf("MSIE"))!=-1){
fullVersion = nAgt.substring(verOffset+5);
}else {
fullVersion = ‘11.0‘;
}
if(fullVersion == 5){
fullVersion = "11.0";
}
browserName = "IE";
}
else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) { // In Chrome, the true version is after "Chrome"
browserName = "Chrome";
fullVersion = nAgt.substring(verOffset+7);
}
else if ((verOffset=nAgt.indexOf("Safari"))!=-1) { // In Safari, the true version is after "Safari" or after "Version"
browserName = "Safari";
fullVersion = nAgt.substring(verOffset+7);
if ((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);
}
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) { // In Firefox, the true version is after "Firefox"
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+8);
}
else if ( (nameOffset=nAgt.lastIndexOf(‘ ‘)+1)
上一篇:jQuery-EasyUI
文章标题:JS 获取当前操作系统类型,浏览器,终端类型的工具
文章链接:http://soscw.com/index.php/essay/104071.html