본문 바로가기
프로그램개발/ClientSide(JavaScript,Angular,Vue)

자바스크립트로 익스플로러 버전 체크

by 크레도스 2021. 3. 18.
<script type="text/javascript">
/* 
 * 원본 : http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie 
 * 수정본 : http://tonks.tistory.com/107 
 */ 
function get_version_of_IE () { 
	 var word; 
	 var agent = navigator.userAgent.toLowerCase(); 
	 // IE old version ( IE 10 or Lower ) 
	 if ( navigator.appName == "Microsoft Internet Explorer" ) word = "msie "; 
	 // IE 11 
	 else if ( agent.search( "trident" ) > -1 ) word = "trident/.*rv:"; 
	 // Microsoft Edge  
	 else if ( agent.search( "edge/" ) > -1 ) word = "edge/"; 
	 // 그외, IE가 아니라면 ( If it's not IE or Edge )  
	 else return -1; 
	 var reg = new RegExp( word + "([0-9]{1,})(\\.{0,}[0-9]{0,1})" ); 
	 if (  reg.exec( agent ) != null  ) return parseFloat( RegExp.$1 + RegExp.$2 ); 
	 return -1; 
} 
</script>