jQuery 1.9不支持$.browser 怎么判断浏览器类型和版本
Query 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合使用 jQuery 1.9 和 2.0, 官方的解决方
jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合使用 jQuery 1.9 和 2.0, 官方的解决方案是:
<!--[if lt IE 9]
<script src='jquery-1.9.0.js'</script
<![endif]--
<!--[if gte IE 9]
<script src='jquery-2.0.0.js'</script
<![endif]--零度科技从长久来看,这样有利于在复杂情况下根据浏览器特性进行分别处理, 而不是简单的检测浏览器类型和版本。 但目前很多旧程序的移植恐怕无法直接过渡为根据浏览器支持特性, 所以在网上找了一些能够直接替换的解决办法。
判断浏览器类型:
$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());
$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
等号后面的表达式返回的就是 true/false, 可以直接用来替换原来的$.browser.msie等。
检查是否为 IE6// Oldif ($.browser.msie && 7 $.browser.version) {}// Newif ('undefined' == typeof(document.body.style.maxHeight)) {}
检查是否为 IE 6-8
if (!$.support.leadingWhitespace) {}
javascript利用jquery-1.7.1来判断是否是谷歌Chrome浏览器
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta charset="utf-8" /> <script src="http://code.jquery.com/jquery-1.7.1.js"></script> </head> <body> <div id="dvshow" style="display:none">请开启极速模式</div> </body> </html> <script> $.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); if ($.browser.chrome) { window.location.href = "index.html"; } else { $("#dvshow").show(); } </script>