javascript浏览器检测
<script type="text/javascript">/** * 获取浏览器类型以及版本号 * 支持国产浏览器:猎豹浏览器、搜狗浏览器、傲游浏览器、360极速浏览器、360安全浏览器、 * QQ浏览器、百度浏览器等. * 支持国外浏览器:IE,Firefox,Chrome,safari,Opera等. * 使用方法: * 获取浏览器版本:Browser.client.version * 获取浏览器名称(外壳):Browser.client.name * @author:xuzengqiang * @since :2015-1-27 10:26:11**/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 : /msie/.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(){ try { return agent.match(/msie ([\d.]+)/)[1] || 0; } 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; } }, //描述:version过滤.如31.0.252.152 只保留31.0 versionFilter:function(){ if(arguments.length === 1 && typeof arguments[0] === "string") { var version = arguments[0]; start = version.indexOf("."); if(start>0){ end = version.indexOf(".",start+1); if(end !== -1) { return version.substr(0,end); } } return version; } else if(arguments.length === 1) { return arguments[0]; } 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("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("error"); } return { client:System }; })(window);alert(Browser.client.name+" "+Browser.client.version);</script>javascript浏览器检测的更多相关文章
- 第一百一十二节,JavaScript浏览器检测
JavaScript浏览器检测 学习要点: 1.navigator对象 2.客户端检测 由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤.虽然浏览器开发商在公共接口方 ...
- JavaScript浏览器检测之navigator 对象
一.使用客户端检测的原因 由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤. 虽然浏览器开发商在公共接口方面投入了很多精力,努力的去支持最常用的公共功能: 但在现实中 ...
- JavaScript浏览器检测之客户端检测
客户端检测一共分为三种,分别为:能力检测.怪癖检测和用户代理检测,通过这三种检测方案,我们可以充分的了解当前浏览器所处系统.所支持的语法.所具有的特殊性能. 一.能力检测: 能力检测又称作为特性检测, ...
- Javascript 浏览器检测
推荐 Browser Detecter, 很好用,自己也很容易扩展. 原文链接:http://www.quirksmode.org/js/detect.html <script type=&qu ...
- JavaScript(第十七天)【浏览器检测】
由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤.虽然浏览器开发商在公共接口方面投入了很多精力,努力的去支持最常用的公共功能:但在现实中,浏览器之间的差异,以及不同浏 ...
- 第一百四十节,JavaScript,封装库--浏览器检测
JavaScript,封装库--浏览器检测 在函数库编写一个,浏览器检测对象 /** sys浏览器检测对象,对象下有两个属性,liu_lan_qi属性和xi_tong属性 * liu_lan_qi属性 ...
- 页面系统,浏览器检测- 网页基础模块(JavaScript)
// 浏览器检测,获取,弹出框提醒IE 返回浏览器详情 function GetbrowserSys() { var BrowserMatch = { init: function() { this. ...
- JavaScript功能检测技术和函数构造
Javascript与很多编程语言不同,它不能够控制其运行环境.再写php代码时,只要在服务器端部署了正确的版本,那么程序就绝对能够运行,对于其他python或ruby后端语言来说,也不存在什么灰色区 ...
- JavaScript交互式网页设计 • 【第3章 JavaScript浏览器对象模型】
全部章节 >>>> 本章目录 3.1 浏览器对象模型 3.1.1 浏览器对象模型 3.2 window 对象 3.2.1 window 对象的常用属性及方法 3.2.2 使 ...
随机推荐
- fhq treap最终模板
新学习了fhq treap,厉害了 先贴个神犇的版, from memphis /* Treap[Merge,Split] by Memphis */ #include<cstdio> # ...
- Ubuntu(Linux) + mono + jexus +asp.net MVC3 部署
感谢 张善友 的建议,我把 微信订餐 由nginx 改成 jexus,目前运行状况来说,确实稳定了很多,再次感谢. 部署步骤参考 jexus官网:http://www.jexus.org/ htt ...
- ASP.NET Web API 路由对象介绍
ASP.NET Web API 路由对象介绍 前言 在ASP.NET.ASP.NET MVC和ASP.NET Web API这些框架中都会发现有路由的身影,它们的原理都差不多,只不过在不同的环境下作了 ...
- WebStorm 常用功能的使用技巧分享
WebStorm 是 JetBrain 公司开发的一款 JavaScript IDE,使用非常方便,可以使编写代码过程更加流畅. 本文在这里分享一些常用功能的使用技巧,希望能帮助大家更好的使用这款强大 ...
- C# 云端-让http自动跳转到https链接
在项目的web.config下面加上下面的配置: <rewrite> <rules> <clear /> <rule name="Redirect ...
- 记一次jdk升级引起的 Unsupported major.minor version 51.0
之前jdk 一直是1.6,tomcat 是6.x 版本,, 现在引入的新的jar, 出现 Caused by: java.lang.UnsupportedClassVersionError: org/ ...
- Android-TextView跑马灯效果
要实现跑马灯还是比较简单的. 同时有几个需要注意的点,先上代码: public class MTView extends TextView { public MTView(Context contex ...
- sqlalchemy学习
sqlalchemy官网API参考 原文作为一个Pythoner,不会SQLAlchemy都不好意思跟同行打招呼! #作者:笑虎 #链接:https://zhuanlan.zhihu.com/p/23 ...
- python描述符理解
Python中的描述符是一个相对底层的概念 descriptor Any object which defines the methods get(), set(), or delete(). Whe ...
- 前端学PHP之mysql扩展函数
× 目录 [1]连接数据库 [2]使用数据库 [3]执行SQL查询[4]操作结果集[5]关闭连接 前面的话 mysql由于其体积小.速度快.总体拥有成本低,尤其是具有开放源码这一特点,许多中小型网站为 ...