本文转自本人上一个博客,”js判断浏览器类型以及版本号(实例)” // <![CDATA[ var isIE = (document.all) ? true : false; document.write(“是否是IE浏览器 “+isIE); document.write(“ ”); var isIE6 = isIE &#038;& ([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 6); var isIE7 = isIE &#038;& ([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 7); var isIE8 = isIE &#038;& ([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 8); document.write(“是否是IE6浏览器 “+isIE6); document.write(“ ”); document.write(“是否是IE7浏览器 “+isIE7); document.write(“ ”); document.write(“是否是IE8浏览器 “+isIE8); document.write(“ ”); document.write(“ ”); document.write(“ ”); function getBrowserVersion() { var browser = {}; var userAgent = navigator.userAgent.toLowerCase(); var s; (s = userAgent.match(/msie ([d.]+)/)) ? browser.ie = s[1] : (s = userAgent.match(/firefox/([d.]+)/)) ? browser.firefox = s[1] : (s = userAgent.match(/chrome/([d.]+)/)) ? browser.chrome = s[1] : (s = userAgent.match(/opera.([d.]+)/)) ? browser.opera = s[1] : (s = userAgent .match(/version/([d.]+).*safari/)) ? browser.safari = s[1] : 0; var version = “”; if (browser.ie) { version = ‘msie ‘ + browser.ie; } else if (browser.firefox) { version = ‘firefox ‘ + browser.firefox; } else if (browser.chrome) { version = ‘chrome ‘ + browser.chrome; } else if (browser.opera) { version = ‘opera ‘ + browser.opera; } else if (browser.safari) { version = ‘safari ‘ + browser.safari; } else { version = ‘未知浏览器’; } return version; } document.write(“浏览器版本号:”+getBrowserVersion()); // ]]>