오른쪽 클릭을 막고싶을 땐 'contextmenu'라는 이벤트가 생길 때 preventDefault속성값을 넣어주면 된다.
contextmenu란 일반적으로 유저와의 상호작용에서 생겨나는 메뉴창같은 것을 칭하고, 대표적으로 '오른쪽 클릭' 이 그것이다.
<script>
document.addEventListener('contextmenu', (event) => {
event.preventDefault();
alert('현재 페이지에서는 오른쪽 클릭 사용이 금지됩니다.');
});
</script>

https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event
Element: contextmenu event - Web APIs | MDN
The contextmenu event fires when the user attempts to open a context menu. This event is typically triggered by clicking the right mouse button, or by pressing the context menu key.
developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault
Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
developer.mozilla.org
'Front-End Developer > JavaScript' 카테고리의 다른 글
누구나 애니메이션 만드는 공식 (0) | 2022.05.18 |
---|---|
함수: 기본중의 기본 정리하기 (0) | 2022.05.18 |
(DOM)click이벤트로 HTML요소 텍스트와 CSS스타일 변경하기 (0) | 2022.05.16 |
하드코드->forEach->이벤트 위임 [점점 나아지는 코드 맛보기] (0) | 2022.05.14 |
blur와 click을 같이 쓸 때, 내 맘대로 안되는 이유 (0) | 2022.05.13 |