상세 컨텐츠

본문 제목

웹페이지 context menu, 소스보기 방지

Web/JavaScript

by 탑~! 2012. 5. 16. 16:30

본문

아래와 모든 페이지의 body tag를 수정해도 돼지만

<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false">

 

아래와 같이 공통으로 include되는 js가 있다면 하나의 수정으로 모두 해결할수 있다.

<script src="/common/js/pluggers.js" ><script>

페이지에 공통적으로 include되는 js파일에 다음과 같이 추가하면 된다.

 

 

pluggers.js에 다음과 같이 추가...

----------------------------------------------------------------------------------------------------

function mouseClickRight() {
  if((event.button == 2) || (event.button == 3)){
    document.body.oncontextmenu = function () { return false; };
    document.body.ondragstart = function () { return false; };
    document.body.onselectstart = function () { return false; };
    return;
  }

document.onmousedown = mouseClickRight;

----------------------------------------------------------------------------------------------------

 

창의 크기가 body보다 클경우 공백에서는 context menu가 나올수 있다 이때는

body에 적용하지 말고 아래와 같이 document에 바로적용하면 해결될것이다.

 

document.oncontextmenu = function () { return false; };

 

 

출처 : http://blog.naver.com/pluggers?Redirect=Log&logNo=150014343586

 

관련글 더보기