日期:2014-05-16 浏览次数:20514 次
function checkIEVersion() { var ua = navigator.userAgent; var s = "MSIE"; var i = ua.indexOf(s) if (i >= 0) { //获取IE版本号 var ver = parseFloat(ua.substr(i + s.length)); alert("你的浏览器是IE"+ver); } else { //其他情况,不是IE alert("你的浏览器不是IE"); } }
function appInfo(){ var browser = {appname: 'unknown', version: 0}, userAgent = window.navigator.userAgent.toLowerCase(); //IE,firefox,opera,chrome,netscape if ( /(msie|firefox|opera|chrome|netscape)\D+(\d[\d.]*)/.test( userAgent ) ){ browser.appname = RegExp.$1; browser.version = RegExp.$2; } else if ( /version\D+(\d[\d.]*).*safari/.test( userAgent ) ){ // safari browser.appname = 'safari'; browser.version = RegExp.$2; } return browser; }
<script> var testBrowser = appInfo(); alert(testBrowser.appname+testBrowser.version); </script>