더 나은 프로그래머가 되자

마우스 우클릭/드래그/선택/키입력 금지 본문

언어/js

마우스 우클릭/드래그/선택/키입력 금지

greathuman 2012. 3. 15. 12:01


방1)

<script language='javascript' type='text/javascript'>

 // 마우스 오른쪽 클릭 방지
 document.oncontextmenu = function(e){
    alert("no right");
    return false;
 }
 // 마우스 드래그 방지
 document.ondragstart = new Function('return false');
 // 마우스 선택 방지
 document.onselectstart = new Function('return false');
 // 키입력 방지
 document.onkeydown = new Function('return false');

</script>

 

 

방2)

<body>
<script language="JavaScript" type="text/javascript">
var msg="마우스 오른쪽버튼 사용금지";
function disableIE() {if (document.all) {alert(!msg);return false;}
}
function disableNS(e) {
  if (document.layers||(document.getElementById&&!document.all)) {
    if (e.which==2||e.which==3) {alert(!msg);return false;}
  }
}
if (document.layers) {
  document.captureEvents(Event.MOUSEDOWN);document.onmousedown=disableNS;
} else {
  document.onmouseup=disableNS;document.oncontextmenu=disableIE;
}
document.oncontextmenu=new Function("alert(msg);return false")
</script>

 바디와 바디사이에 추가
</body>

 

Comments