JS, CSS, jQuery, HTML, AJAX/JavaScript
Javascript - onselectstart Event / IE 브라우저 한글 자음,모음 분리
littlemk
2020. 3. 25. 15:46
<html>
<head>
<script>
function myFunc(){
alert("선택불가");
return false;
}
</script>
</head>
<body onselectstart = "return myFunc();">
<input type="text">
</body>
</html>
위의 경우 IE 빼고 크롬에서는 정상적으로 동작된다.
허나.. IE를 사용하는 분들도 있기 때문에 위와 같이 사용하게 되면 한글 입력시 "선택불가" alert 창이 계속해서 노출될 것이다.
이럴때 야매(?)로 쓰기 좋은 방법은 바로 css를 이용하는 것이다.
위의 코드를 아래의 코드로 사용하면 된다.
ps. 전체 감싸고 싶으면 body에 class 둘 것
<html>
<head>
<style>
.no-drag {-ms-user-select: none; -moz-user-select: -moz-none; -webkit-user-select: none; -khtml-user-select: none; user-select:none;}
</style>
</head>
<body class="no-drag">
<input type="text">
</body>
</html>