1. 程式人生 > >html禁用滑鼠右鍵

html禁用滑鼠右鍵

1.在js中新增如下程式碼:

<script type="text/javascript">


function disableRightClick(e){
  var message = "右鍵禁用...";
 
   if(!document.rightClickDisabled){
 if(document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = disableRightClick;
  }else document.oncontextmenu = disableRightClick;
  return document.rightClickDisabled = true;
   }
   if(document.layers || (document.getElementById && !document.all)){
  if (e.which==2||e.which==3){
    return false;
  }
   }else{
  return false;
   }
 }
  disableRightClick();

</script>

2.在body中新增

<body oncontextmenu=self.event.returnValue=false onselectstart="return false">