본문 바로가기

HTML DOM Events | oncontextmenu 이벤트

반응형

마우스 오른쪽 상황에 맞는 메뉴가 표시되지 않도록 방지

div.addEventListener("contextmenu", (e) => {e.preventDefault()});
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The contextmenu Event</h2>

<div style="border:1px solid black;text-align:center">
<p>Right-click in this box!</p>
<p>Context menu will show.</p>
</div>
<br>
<div id="myDiv" style="border:1px solid black;text-align:center">
<p>Right-click in this box!</p>
<p>Context menu is disabled.</p>
</div>

<script>
const div = document.getElementById("myDiv");
div.addEventListener("contextmenu", (e) => {e.preventDefault()});
</script>

</body>
</html>

 

HTML DOM Events

The contextmenu Event

Right-click in this box!

Context menu will show.


Right-click in this box!

Context menu is disabled.

 

반응형

댓글


Copyright ⓒ SmartWeb All rights reserved.