function getOsInfo() {
var userAgent = navigator.userAgent.toLowerCase();
var name = 'Unknown';
var version = "Unknown";
if(userAgent.indexOf("win") > -1) {
name = "Windows";
if(userAgent.indexOf("windows nt 5.0") > -1) {
version = "Windows 2000";
} else if(userAgent.indexOf("windows nt 5.1") > -1 || userAgent.indexOf("windows nt 5.2") > -1) {
version = "Windows XP";
} else if(userAgent.indexOf("windows nt 6.0") > -1) {
version = "Windows Vista";
} else if(userAgent.indexOf("windows nt 6.1") > -1 || userAgent.indexOf("windows 7") > -1) {
version = "Windows 7";
} else if(userAgent.indexOf("windows nt 6.2") > -1 || userAgent.indexOf("windows 8") > -1) {
version = "Windows 8";
} else if(userAgent.indexOf("windows nt 6.3") > -1) {
version = "Windows 8.1";
} else if(userAgent.indexOf("windows nt 6.2") > -1 || userAgent.indexOf("windows nt 10.0") > -1) {
version = "Windows 10";
} else {
version = "Unknown";
}
} else if(userAgent.indexOf("iphone") > -1) {
name = "Iphone";
} else if(userAgent.indexOf("mac") > -1) {
name = "Mac";
} else if(userAgent.indexOf("x11") > -1 || userAgent.indexOf("unix") > -1 || userAgent.indexOf("sunname") > -1 || userAgent.indexOf("bsd") > -1) {
name = "Unix";
} else if(userAgent.indexOf("linux") > -1) {
if(userAgent.indexOf("android") > -1) {
name = "Android"
} else {
name = "Linux";
} } else {
name = "Unknown";
}
var os = new Object();
os.name = name;
os.version = version;
return os;
//document.write("系统:" + os.name + "版本:" + os.name)
}
function getBrowerInfo(){
var Browser = Browser || (function(window) {
var document = window.document,
navigator = window.navigator,
agent = navigator.userAgent.toLowerCase(),
//IE8+支持.返回浏览器渲染当前文档所用的模式
//IE6,IE7:undefined.IE8:8(兼容模式返回7).IE9:9(兼容模式返回7||8)
//IE10:10(兼容模式7||8||9)
IEMode = document.documentMode,
//chorme
chrome = window.chrome || false,
System = {
//user-agent
agent: agent,
//是否为IE
isIE: /trident/.test(agent),
//Gecko内核
isGecko: agent.indexOf("gecko") > 0 && agent.indexOf("like gecko") < 0,
//webkit内核
isWebkit: agent.indexOf("webkit") > 0,
//是否为标准模式
isStrict: document.compatMode === "CSS1Compat",
//是否支持subtitle
supportSubTitle: function() {
return "track" in document.createElement("track");
},
//是否支持scoped
supportScope: function() {
return "scoped" in document.createElement("style");
}, //获取IE的版本号
ieVersion: function() {
var rMsie  = /(msie\s|trident.*rv:)([\w.]+)/;
var ma = window.navigator.userAgent.toLowerCase()
var  match  = rMsie.exec(ma);  
try {
return match[2];
} catch (e) {
// console.log("error");
return IEMode;
}
},
//Opera版本号
operaVersion: function() {
try {
if (window.opera) {
return agent.match(/opera.([\d.]+)/)[1];
} else if (agent.indexOf("opr") > 0) {
return agent.match(/opr\/([\d.]+)/)[1];
}
} catch (e) {
// console.log("error");
return 0;
}
}
}; try {
//浏览器类型(IE、Opera、Chrome、Safari、Firefox)
System.type = System.isIE ? "IE" :
window.opera || (agent.indexOf("opr") > 0) ? "Opera" :
(agent.indexOf("chrome") > 0) ? "Chrome" :
//safari也提供了专门的判定方式
window.openDatabase ? "Safari" :
(agent.indexOf("firefox") > 0) ? "Firefox" :
'unknow'; //版本号
System.version = (System.type === "IE") ? System.ieVersion() :
(System.type === "Firefox") ? agent.match(/firefox\/([\d.]+)/)[1] :
(System.type === "Chrome") ? agent.match(/chrome\/([\d.]+)/)[1] :
(System.type === "Opera") ? System.operaVersion() :
(System.type === "Safari") ? agent.match(/version\/([\d.]+)/)[1] :
"0"; //浏览器外壳
System.shell = function() { if (agent.indexOf("edge") > 0) {
System.version = agent.match(/edge\/([\d.]+)/)[1] || System.version;
return "edge浏览器";
}
//遨游浏览器
if (agent.indexOf("maxthon") > 0) {
System.version = agent.match(/maxthon\/([\d.]+)/)[1] || System.version;
return "傲游浏览器";
}
//QQ浏览器
if (agent.indexOf("qqbrowser") > 0) {
System.version = agent.match(/qqbrowser\/([\d.]+)/)[1] || System.version;
return "QQ浏览器";
} //搜狗浏览器
if (agent.indexOf("se 2.x") > 0) {
return '搜狗浏览器';
} //Chrome:也可以使用window.chrome && window.chrome.webstore判断
if (chrome && System.type !== "Opera") {
var external = window.external,
clientInfo = window.clientInformation,
//客户端语言:zh-cn,zh.360下面会返回undefined
clientLanguage = clientInfo.languages; //猎豹浏览器:或者agent.indexOf("lbbrowser")>0
if (external && 'LiebaoGetVersion' in external) {
return '猎豹浏览器';
}
//百度浏览器
if (agent.indexOf("bidubrowser") > 0) {
System.version = agent.match(/bidubrowser\/([\d.]+)/)[1] ||
agent.match(/chrome\/([\d.]+)/)[1];
return "百度浏览器";
}
//360极速浏览器和360安全浏览器
if (System.supportSubTitle() && typeof clientLanguage === "undefined") {
//object.key()返回一个数组.包含可枚举属性和方法名称
var storeKeyLen = Object.keys(chrome.webstore).length,
v8Locale = "v8Locale" in window;
return storeKeyLen > 1 ? '360极速浏览器' : '360安全浏览器';
}
return "Chrome";
}
return System.type;
}; //浏览器名称(如果是壳浏览器,则返回壳名称)
System.name = System.shell();
//对版本号进行过滤过处理
// System.version = System.versionFilter(System.version); } catch (e) {
// console.log(e.message);
}
return {
client: System
}; })(window);
if (Browser.client.name == undefined || Browser.client.name=="") {
Browser.client.name = "Unknown";
Browser.client.version = "Unknown";
}else if(Browser.client.version == undefined){
Browser.client.version = "Unknown";
}
// document.write(Browser.client.name + " " + Browser.client.version);
return Browser ;
}

自己备用

【转】通过js获取系统版本以及浏览器版本的更多相关文章

  1. JS获取当前使用的浏览器名字以及版本号

    JS获取当前使用的浏览器名字以及版本号 工作中需要通过JS去获取当前使用的浏览器的名字以及版本号,网上大堆资料都有一个关键词是 navigator.appName,但是这个方法获取的浏览器的名字只有两 ...

  2. .NET 获取客户端的操作系统版本、浏览器版本和IP地址

    我们在使用.NET做网站的时候,很多情况下需要需要知道客户端的操作系统版本和浏览器版本,怎样获取客户端的操作系统和浏览器版本呢?我们可以通过分析UserAgent来获取. .NET 获取客户端的操作系 ...

  3. 原生JS获取DOM 节点到浏览器顶部的距离或者左侧的距离

    关于js获取dom 节点到浏览器顶/左部的距离,Jquery里面有封装好的offset().top/offset().left,只到父级的顶/左部距离position().top/position() ...

  4. Js获取操作系统版本 && 获得浏览器版本

    //利用原生Js获取操作系统版本function getOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.plat ...

  5. js获取系统的根路径实现介绍

    js如何获取系统的根路径,在本文给出了详细的方法 function getBasePath(){ var obj=window.location; var contextPath=obj.pathna ...

  6. js 获取系统当前时间

    JS获取当前的日期和时间的方法:var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年 ...

  7. js获取页面元素距离浏览器工作区顶端的距离

    先介绍几个属性:(暂时只测了IE和firefox,实际上我工作中用到的最多的是chrome)  网页被卷起来的高度/宽度(即浏览器滚动条滚动后隐藏的页面内容高度) (javascript)       ...

  8. JS获取系统的指定定年月日

    /** * 获取系统当前时间 */ function getNowYearMouth(){ var date=new Date; var nowYearMouth=date.getMonth()+1; ...

  9. js网页判断移动终端浏览器版本信息是安卓还是苹果ios,判断在微信浏览器跳转不同页面,生成二维码

    一个二维码,扫描进入网页,自动识别下载苹果和安卓客户端,判断网页如下,(只有苹果的微信不能自动跳转)所以加个微信判断. <!DOCTYPE html> <html> <h ...

随机推荐

  1. Tomcat架构解析(一)-----Tomcat总体架构

    Tomcat是非常常用的应用服务器,了解Tomcat的总体架构以及实现细节,对于理解整个java web也是有非常大的帮助. 一.Server   1.最简单的服务器结构 最简单的服务器结构如图所示: ...

  2. s5-10 路由

    路由器转发分组的依据 路由表 路由表从何而来 直连路由.静态路由.动态路由 路由器收到一个分组之后-  打开分组L3,提取出目的IP地址  确定目标网络,查找路由表 按位"AND&quo ...

  3. CSS定位之position详解

    position属性 在前端中,position是很常见的属性.通过这个属性可以调整dom元素在浏览器中显示的位置. 它有几个常用的属性: static 默认值.通常是在覆盖absolute或者rel ...

  4. Windows窗口消息大全

    ////////////////////////////////////////////////////////////////////////// #include "AFXPRIV.H& ...

  5. 整理mianshi2

    1.性能优化相关https://www.cnblogs.com/cr330326/p/8011523.html 2.CountDownLatchjava共享锁实现原理及CountDownLatch解析 ...

  6. C++函数的传值调用&指针调用&引用调用

    目录 传值调用 指针调用 引用调用 传值调用 该方法把参数的实际值复制给函数的形式参数.在这种情况下,修改函数内的形式参数对实际参数没有影响. #include<iostream> usi ...

  7. wx.setStorageSync(KEY,DATA)

    wx.setStorageSync 每个微信小程序都可以有自己的本地缓存,可以通过wx.setStorage(wx.setStorageSync).wx.getStorage(wx.getStorag ...

  8. 准备用有人云平台和tlink.io云平台和电脑做云转发

    初步想的是用有人做国网电表转发,用tlink.io做综合采集模块转发,耗时一天 然后用tlink.io的做二次前端开发,耗时两天 用有人做二次前端开发,耗时两天 最后可以试试用常见的OPC公网转发到这 ...

  9. Max Sum—hdu1003(简单DP) 标签: dp 2016-05-05 20:51 92人阅读 评论(0)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  10. Form表单中的action提交路径问题

    Form表单中的action提交路径问题 Form表单action属性和method属性的一些问题: 我遇到的是Form表单提交到servelet处理时遇到的问题:(1)<form name=& ...