코딩방/트러블슈팅
[JavaScript] 브라우저 확인
devheedoo
2017. 5. 24. 17:59
브라우저 확인: IE
<!-- Tested on 2016. 12. 5. --> <body> <!-- IE8 --> <!--[IF IE 8]> <p>isIE8</p> <![endif]--> <!-- IE9 --> <!--[IF IE 9]> <p>isIE9</p> <![endif]--> <!-- Conditional Comment no longer works since IE10 --> <!-- So we use JavaScript --> <div id="isIE10"></div> <div id="isIE11"></div> <script> $(document).ready(function() { // IE10 if (Function('/*@cc_on return document.documentMode===10@*/')()) { console.log('IE10'); $('#isIE10').append('<p>IE10</p>'); } // IE11 if (/Trident.*rv[ :]*11\./.test(navigator.userAgent)) { console.log('IE11'); $('#isIE11').append('<p>IE11</p>'); } }); </script> </body>
브라우저 확인: Chrome
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);