jQuery浏览器版本判断
jQuery 浏览器判断,jQuery提供了一个 jQuery.browser 方法 来判断浏览器
可用值:
safari opera msie mozilla
例如:
if($.browser.msie){ alert("Microsoft Internet Explorer")}
if($.browser.mozilla){ alert("Mozilla Firefox")}
当然有时候我们还需要区分版本 这就要用到 jQuery.browser.version
例如:
if($.browser.msie){ alert($.browser.version)}
你可能得到 6.0 7.0 或者其他 等等
下面是一个较为完整的例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://www.titan24.com/scripts/jquery-1.2.6.pack.js"></script>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#eee;}
.info{ width:600px; min-height:120px; _height:120px; line-height:120px; border:8px solid #f60; margin:40px auto; background:#fff; text-align:center; font-size:36px; font-weight:900; font-family:Arial, Helvetica, sans-serif; color:#d00;}
</style>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
var bro=$.browser;
var binfo="";
if(bro.msie) {binfo="Microsoft Internet Explorer "+bro.version;}
if(bro.mozilla) {binfo="Mozilla Firefox "+bro.version;}
if(bro.safari) {binfo="Apple Safari "+bro.version;}
if(bro.opera) {binfo="Opera "+bro.version;}
alert(binfo);
$("#browser").html(binfo);
})
/* ]]> */
</script>
</head>
<body>
<div id="browser" class="info">
Browser Info
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://www.titan24.com/scripts/jquery-1.2.6.pack.js"></script>
<style type="text/css">
*{ margin:0; padding:0;}
body{ background:#eee;}
.info{ width:600px; min-height:120px; _height:120px; line-height:120px; border:8px solid #f60; margin:40px auto; background:#fff; text-align:center; font-size:36px; font-weight:900; font-family:Arial, Helvetica, sans-serif; color:#d00;}
</style>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
var bro=$.browser;
var binfo="";
if(bro.msie) {binfo="Microsoft Internet Explorer "+bro.version;}
if(bro.mozilla) {binfo="Mozilla Firefox "+bro.version;}
if(bro.safari) {binfo="Apple Safari "+bro.version;}
if(bro.opera) {binfo="Opera "+bro.version;}
alert(binfo);
$("#browser").html(binfo);
})
/* ]]> */
</script>
</head>
<body>
<div id="browser" class="info">
Browser Info
</div>
</body>
</html>