浏览器的内核及版本的判断
生活随笔
收集整理的這篇文章主要介紹了
浏览器的内核及版本的判断
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通過jquery 判斷瀏覽器的內核及版本號
<script type="text/javascript">$(function () {if ($.browser.msie && ($.browser.version == "7.0")) {$("#yourannet").css("margin-left", "10px");} //IE7瀏覽器else if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {$("#yourannet").css("margin-left", "15px");} //IE6瀏覽器else if ($.browser.msie && ($.browser.version == "8.0")) {$("#yourannet").css("margin-left", "20px");} //IE8瀏覽器else if ($.browser.msie && ($.browser.version == "9.0")) {$("#yourannet").css("margin-left", "25px");} // IE9 瀏覽器else if (window.navigator.userAgent.toLowerCase().indexOf("360se") >= 1) {$("#yourannet").css("margin-left", "30px");}//360瀏覽器})
jQuery 使用的是通過正則來匹配userAgent判斷瀏覽器的種類和版本. 如果我們要來判斷當前瀏覽器是否是IE6應該如何來判斷? $(function() {if($.browser.msie) {alert("this is msie"); } else if($.browser.safari) {alert("this is safari!"); } else if($.browser.mozilla) {alert("this is mozilla!"); } else if($.browser.opera) {alert("this is opera"); } else {alert("i don't konw!"); }
以下是jquery的正則表達式:支持區分ie、firefox、opera、chrome、safari // browser check-----startvar userAgent = navigator.userAgent, // userAgentrMsie = /.*(msie) ([\w.]+).*/, // ierFirefox = /.*(firefox)\/([\w.]+).*/, // firefoxrOpera = /(opera).+version\/([\w.]+)/, // operarChrome = /.*(chrome)\/([\w.]+).*/, // chromerSafari = /.*version\/([\w.]+).*(safari).*/;// safarijMeteor.browser = {};var ua = userAgent.toLowerCase();function uaMatch(ua) {var match = rMsie.exec(ua);if (match != null) {return { browser : match[1] || "", 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) {jMeteor.browser[browserMatch.browser] = true;jMeteor.browserName = browserMatch.browser;jMeteor.browser.version = browserMatch.version;jMeteor.browser.language = (navigator.language ? navigator.language: navigator.userLanguage || "");}// browser check-----end
使用方法:Javascript代碼jMeteor.browser.msie //判斷是否為ie,返回true則代表是jMeteor.browserName //瀏覽器名稱jMeteor.browser.version //瀏覽器版本jMeteor.browser.language //語言 </script>
通過瀏覽器版本信息判斷各瀏覽器
var _uat=navigator.userAgent;?
if(_uat.indexOf("MSIE 6.0")>0) alert("ie6");?
else if(_uat.indexOf("MSIE 7.0")>0) alert("ie7");?
else if(_uat.indexOf("MSIE 8.0")>0) alert("ie8");?
else if(_uat.indexOf("Firefox")>0) alert("firefox");?
CSS判斷瀏覽器?
#example{color:red ;} /*firefox*/?
* html #example{color:blue;} /*ie6*/?
*+html #example{color:green;} /*ie7*/?
HTML判斷瀏覽器?
1. <!--[if !IE]><!-->除IE外都可識別<!--<![endif]-->?
2. <!--[if IE]> 所有的IE可識別<![endif]-->?
3. <!--[if IE 6]> 僅IE6可識別<![endif]-->?
4.<!--[if lt IE 6]> IE6以及IE6以下版本可識別<![endif]-->?
5. <!--[if gte IE 6]> IE6以及IE6以上版本可識別<![endif]-->?
6.<!--[if IE 7]> 僅IE7可識別<![endif]-->?
7. <!--[if lt IE 7]> IE7以及IE7以下版本可識別<![endif]-->?
8. <!--[if gte IE 7]> IE7以及IE7以上版本可識別<![endif]-->?
轉載于:https://www.cnblogs.com/nancy0324/archive/2013/03/22/2975033.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的浏览器的内核及版本的判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 强大的PHP防SQL注入类,可以过滤敏感
- 下一篇: 2017年html5行业报告,云适配发布