首页 >

浏览器检测JS代码(兼容目前各大主流浏览器)【javascript】

web前端|js教程浏览器检测JS代码(兼容目前各大主流浏览器)【javascript】
JS,浏览器,检测
web前端-js教程
本文实例介绍了JS代码实现浏览器检测,分享给大家供大家参考,具体内容如下
安卓图片旋转源码,逻辑分区安装ubuntu,tomcat报错日志是哪个,Python爬虫贵州,php代码打印教程,seo技术 乐云seolzw
var BrowserMatch = {  init: function () {    this.browser = this.getBrowser().browser || "An Unknown Browser";    this.version = this.getBrowser().version || "An Unknown Version";    this.OS = this.getOS() || "An Unknown OS";  },  getOS:function(){    if(navigator.platform.indexOf("Win")!= -1) return "Windows";    if(navigator.platform.indexOf("Mac")!= -1) return "Mac";    if(navigator.platform.indexOf("Linux")!= -1) return "Linux";    if(navigator.userAgent.indexOf("iPhone")!= -1) return "iPhone/iPod";  },  getBrowser:function () {    var rMsie = /(msie\s|trident\/7)([\w\.]+)/;    var rTrident = /(trident)\/([\w.]+)/;    var rFirefox = /(firefox)\/([\w.]+)/;     var rOpera = /(opera).+version\/([\w.]+)/;    var rNewOpera = /(opr)\/(.+)/;    var rChrome = /(chrome)\/([\w.]+)/;    var rSafari = /version\/([\w.]+).*(safari)/;    var ua = navigator.userAgent.toLowerCase();    var matchBS,matchBS2;    matchBS = rMsie.exec(ua);    if (matchBS != null) {      matchBS2 = rTrident.exec(ua);      if (matchBS2 != null){        switch (matchBS2[2]){          case "4.0": return { browser : "IE", version : "8" };break;          case "5.0": return { browser : "IE", version : "9" };break;          case "6.0": return { browser : "IE", version : "10" };break;          case "7.0": return { browser : "IE", version : "11" };break;          default:return { browser : "IE", version : "Undefined" };        }      }else{        return {browser : "IE", version : matchBS[2] || "0" };      }    }    matchBS = rFirefox.exec(ua);      if ((matchBS != null)&&(!(window.attachEvent))&&(!(window.chrome))&&(!(window.opera))) {        return { browser : matchBS[1] || "", version : matchBS[2] || "0" };    }    matchBS = rOpera.exec(ua);             if ((matchBS != null)&&(!(window.attachEvent))) {           return { browser : matchBS[1] || "", version : matchBS[2] || "0" };    }    matchBS = rChrome.exec(ua);      if ((matchBS != null)&&(!!(window.chrome))&&(!(window.attachEvent))) {      matchBS2 = rNewOpera.exec(ua);             if(matchBS2 == null){        return { browser : matchBS[1] || "", version : matchBS[2] || "0" };      }else{        return { browser : "Opera", version : matchBS2[2] || "0" };      }      }    matchBS = rSafari.exec(ua);              if ((matchBS != null)&&(!(window.attachEvent))&&(!(window.chrome))&&(!(window.opera))) {         return { browser : matchBS[2] || "", version : matchBS[1] || "0" };    }             }};  BrowserMatch.init();
调用方法:(首先得引入js文件,大家应该都懂的)
java网络调试助手源码,vscode sysgcc,ubuntu外接显示器,tomcat调优的几种配置方式,sqlite 插入性能,网页设计主要收获,怎么看服务器到期,级联下拉列表 插件,前端开发框架APP,淘大象爬虫,php charat,启东SEO,爱码平台网站源码,网页制作内容右下角,卡通网页模板,wordpress 页面如何打开评论,java版的企业人事管理系统完整版源码,e语言程序界面怎么改lzw
获取浏览器名:BrowserMatch.browser;
排队返现系统源码,vscode误触上下箭头,ubuntu命令null,tomcat dv证书,sqlite语句哪出问题了,房间顶四周绿爬虫,php查询函数,seo页面简介字符数量,用wordpress搭建的网站,没有后台管理器怎么更新网页内容,dedecms 模板怎么用判断lzw
获取浏览器版本:BrowserMatch.version;

获取所处操作系统:BrowserMatch.OS;


  • 暂无相关文章
  • Posted in 未分类