Skip to content

JavaScript:Example:DisableRightMouseButton

일명 "불펌방지" 기능. 마우스 오른쪽 버튼 메뉴를 제거한다.

JavaScript Code

자바스크립트 코드는 다음과 같다:

const omitformtags = ["input", "textarea", "select"].join("|");

function disableselect(e) {
    if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1) {
        return false
    }
}

function reEnable(){
    return true
}

if (typeof document.onselectstart!="undefined") {
    document.onselectstart = new Function ("return false");
} else {
    document.onmousedown = disableselect;
    document.onmouseup = reEnable;
}

다시 이 기능 켜기

역으로 이 기능을 제거하고 싶다면 관련 스크립트를 제거하자.

Chrome의 F12로 시작하는 개발자 모드의, Console 탭에서

window.oncontextmenu = null;
document.oncontextmenu = null;

전체 tag의 루프 버전:

for(var id = 0; id < document.getElementsByTagName("*").length; ++id) { elements[id].oncontextmenu = null; }

참고로, firefox는 안되더라...

See also