js 去掉浏览器右击默认事件

1.整个页面所有的右击事件

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

2.特定的区域

document.getElementById("test").oncontextmenu = function(e){
  return false;
}

3.去掉后可以给喜欢区块加特定的事件

js:

document.getElementById("test").onmousedown = function(e){
  if(e.button ==2){
    alert("你点了右键");
  }else if(e.button ==0){
    alert("你点了左键");
  }else if(e.button ==1){
    alert("你点了滚轮");
  }
}

jq:

$("#test").mousedown(function(e){
  //doing
});

4.通过jq  bind 绑定 和 触发

$('').bind("contextmenu",function (e){

   //doning

   return false;

});

$('').trigger('contextmenu');

原文地址:https://www.cnblogs.com/zycbloger/p/5643122.html