JS 전체 호환 검사 브라우저 유형 및 버전

2674 단어 브라우저 유형
직접 코드:
<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>

좋은 웹페이지 즐겨찾기