转载 jQuery浏览器版本判断
可用值:
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 或者其他 等等
下面是一个较为完整的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title>无标题文档</title> <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><br><br>转自:http: //www.cnblogs.com/trance/archive/2009/04/29/1446192.html<br> <script type="text/javascript">
var browser=navigator.appName var b_version=navigator.appVersion var version=b_version.split(";"); var trim_Version=version[1].replace(/[ ]/g,""); if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") { alert("IE 7.0"); } else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") { alert("IE 6.0"); } </script> |