JS全兼容检测浏览器类型及版本
直接上代码:
<script> var browser = (function () { var isIE6 = /msie 6/i.test(navigator.userAgent); var isIE7 = /msie 7/i.test(navigator.userAgent); var isIE8 = /msie 8/i.test(navigator.userAgent); var isIE9 = /msie 9/i.test(navigator.userAgent); var isIE = /msie/i.test(navigator.userAgent); var isFireFox = /firefox/i.test(navigator.userAgent); var isChrome = /Chrome/i.test(navigator.userAgent); return { msie: isIE, version: function () { switch (true) { case isIE6: return 6; case isIE7: return 7; case isIE8: return 8; case isIE9: return 9; case isFireFox: return "火狐"; case isChrome: return "谷歌"; } }() }; })(); alert(browser.msie); alert(browser.version); </script>