<!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title>判断浏览器及其版本</title> <script type="text/javascript"> window.onload = function() { //alert(navigator.cookieEnabled); //ÅжÏÊÇ·ñÖ§³Öcookie var b = browsers(); document.write("当前浏览器是" + b.name + "<br/>版本号是" + b.v); } var browsers = function() { var sys = {}; var ua = navigator.userAgent.toLowerCase(); var browser; var s; if(ua.match(/chrome\/\d+/)) { s = ua.match(/chrome\/\d+/)[0].split("/"); sys.name = "Chrome"; sys.v = s[1]; } else if(ua.match(/msie \d+/)) { s = ua.match(/msie \d+/)[0].split(" "); sys.name = "IE"; sys.v = s[1]; } else if(ua.match(/firefox\/\d+/)) { s = ua.match(/firefox\/\d+/)[0].split("/"); sys.name = "FireFox"; sys.v = s[1]; } else if(ua.match(/opera\/\d+/)) { s = ua.match(/opera\/\d+/)[0].split("/"); sys.name = "Opera"; sys.v = s[1]; } else { sys.name = "该浏览器无法识别"; sys.v = 0; } return sys; } </script> </head> <body> </body> </html>