📜  如何在右键单击时添加功能 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:45.598000             🧑  作者: Mango

代码示例1
if (document.addEventListener) {
  document.addEventListener('contextmenu', function(e) {
    alert("You've tried to open context menu"); //here you draw your own menu
    e.preventDefault();
  }, false);
} else {
  document.attachEvent('oncontextmenu', function() {
    alert("You've tried to open context menu");
    window.event.returnValue = false;
  });
}