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. c#多线程编程实战(原书第二版)文摘

    Thread t = new Thread(PrintNumbersWithDelay); t.Start(); t.Join(); 但我们在主程序中调用了t.Join方法,该方法允许我们等待直到线程 ...

  2. js,javascript,删除元素,创建元素,插入子元素

    删除元素示例代码 <html> <head> </head> <body> <div> <div id="delId&quo ...

  3. asp.net下配置使用Memcached 如何使用Memcached .ne使用BeITMemcached.dllt配置Memcached的方法

    首先在项目中引用 BeITMemcached.dll 在Web.config中配置节点 <configSections> <section name="beitmemcac ...

  4. java通过sftp对linux服务器文件夹进行操作

    本文主要讲sftp对linux服务器的文件和文件夹进行操作,windows server 服务器不支持. package com.lx.ftp; import java.io.File; import ...

  5. Struts2--HelloWord

    Struts2官网 官网指南 官网下载Struts2.5-min-lib.zip解压把lib目录下jar包拷贝到web项目lib目录下 配置web.xml文件 <filter> <f ...

  6. Jack Straws(poj 1127) 两直线是否相交模板

    http://poj.org/problem?id=1127   Description In the game of Jack Straws, a number of plastic or wood ...

  7. 如何更改linux文件的拥有者及用户组(chown和chgrp)

    http://blog.csdn.net/hudashi/article/details/7797393 一.基本知识   在Linux中,创建一个文件时,该文件的拥有者都是创建该文件的用户.该文件用 ...

  8. 实用shell命令100条

    1,echo "aa" > test.txt 和 echo "bb" >> test.txt //>将原文件清空,并且内容写入到文件中, ...

  9. set_error_handler

    set_error_handler这个函数的作用是为了防止错误路径泄露 何为错误路径泄露呢? 我们写程序,难免会有问题,而PHP遇到错误时,就会给出出错脚本的位置.行数和原因 有很多人说,这并没有什么 ...

  10. ubuntu16.04 LTS把下载源改为阿里云的源

    为什么要切换下载源到国内的源上? Ubuntu的中国服务器下载速度很慢,我们可以尝试修改软件更新源,这样下载和更新软件的速度会加快很多. 一.linux系统版本: ubuntukylin-16.04- ...