首页 > 代码库 > JS检测浏览器版本信息(包含IE11),并动态添加样式
JS检测浏览器版本信息(包含IE11),并动态添加样式
<head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="Scripts/jquery-1.9.1.min.js"></script> <link href="" rel="stylesheet" /><%--这里可以链接一个默认的样式表(link 标签一定不能丢,不然后面 document.getElementsByTagName("link")[0].href = title;会报错)--%> <script> $(function () { var userAgent = navigator.userAgent, rMsie = /(msie\s|trident.*rv:)([\w.]+)/, rFirefox = /(firefox)\/([\w.]+)/, rOpera = /(opera).+version\/([\w.]+)/, rChrome = /(chrome)\/([\w.]+)/, rSafari = /version\/([\w.]+).*(safari)/; var browser; var version; var ua = userAgent.toLowerCase(); function uaMatch(ua) { var match = rMsie.exec(ua); if (match != null) { return { browser: "IE", version: match[2] || "0" }; } var match = rFirefox.exec(ua); if (match != null) { return { browser: match[1] || "", version: match[2] || "0" }; } var match = rOpera.exec(ua); if (match != null) { return { browser: match[1] || "", version: match[2] || "0" }; } var match = rChrome.exec(ua); if (match != null) { return { browser: match[1] || "", version: match[2] || "0" }; } var match = rSafari.exec(ua); if (match != null) { return { browser: match[2] || "", version: match[1] || "0" }; } if (match != null) { return { browser: "", version: "0" }; } } var browserMatch = uaMatch(userAgent.toLowerCase()); if (browserMatch.browser) { browser = browserMatch.browser; version = browserMatch.version; } var BVSN = (browser + version); if (BVSN == "IE11.0") { setStyle("style/ie11.css");//这里是样式表的路径 } else if (BVSN == "IE10.0") { setStyle("style/ie10.css"); } else if (BVSN == "IE8.0") { setStyle("style/ie8.css"); } else if (BVSN.indexOf("chrome") > -1) { setStyle("style/chrome.css"); } else if (BVSN.indexOf("firefox") > -1) { setStyle("style/firefox.css"); } var width = window.screen.width;//获取浏览器宽度 var height = window.screen.height;//获取浏览器高度 }); function setStyle(title) { document.getElementsByTagName("link")[0].href = title; } </script> </head>
JS检测浏览器版本信息(包含IE11),并动态添加样式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。