This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

GlobalEventHandlers.oncontextmenu

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

윈도우에서 마우스 오른쪽 클릭시 발생하는 이벤트 이벤트 핸들러 속성 입니다. 기본동작을 막지 않는 한 (아래의 예제를 참조하세요), 브라우저의 컨텍스트 메뉴가 활성화됩니다. (그러나 IE8는 이것과 관련된 버그가 있어 contextmenu 가 정의 되어있다고 할지라도 활성화 되지 않습니다). 이 이벤트는 비활성화되지 않은(non-disabled) 오른쪽 클릭 이벤트와 함께 발생하며 "contextmenu" 속성 을 가진 엘리먼트에는 달리지 않는다는 것을 유의하세요.

Syntax

js
window.oncontextmenu = funcRef;
//funcRef refers to the function to be called

Example

페이지상에서 오른쪽 클릭을 막는 예제들 입니다:

js
document.oncontextmenu = function () {
  // Use document as opposed to window for IE8 compatibility
  return false;
};

window.addEventListener(
  "contextmenu",
  function (e) {
    // Not compatible with IE < 9
    e.preventDefault();
  },
  false,
);

명세서

Specification
UI Events
# event-type-contextmenu

브라우저 호환성