簡體   English   中英

鼠標:禁用右鍵和中鍵單擊

[英]mouse : disable right and middle button click

我用過這個但它不起作用; 螢火蟲沒有錯誤:

$("div").live('mousedown', function(e) { 
   if( (e.which == 1) ) {
     return ;
   }if( (e.which == 3) ) {
     return false;
   }else if( (e.which == 2) ) {
      return false; 
   }
})

我可以禁用右鍵單擊contextmenu但我不知道如何處理中鍵。

您可以使用Javascript和/或HTML屬性(無論如何,這實際上是一個Javascript事件處理程序),如此處所述

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(e)
{
   if (e.button == 2) {
     alert(status);
     return false;    
   }
}
</script>

<body oncontextmenu="return false">
...
</body>

話雖如此:不要做。

為什么? 因為它除了煩人的用戶之外什么都沒有。 此外,許多瀏覽器都有一個安全選項,禁止禁用右鍵單擊(上下文)菜單。

不知道為什么你想要。 如果出於某種錯誤的信念,你可以用這種方式保護你的源代碼或圖像,那就再想一想:你做不到。

您錯過了代碼中的“其他”。

$("div").live('mousedown', function(e) { 
   if( (e.which == 1) ) {
     return ;
   }else if( (e.which == 3) ) {
     return false;
   }else if( (e.which == 2) ) {
      return false; 
   }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM