js 阻止右击

漫思 / 2024-02-03 / 原文


js 阻止右击

在JavaScript中可以使用addEventListener()函数来添加事件处理程序。要阻止右击(context menu)的默认行为,我们需要将其设置为false或者调用preventDefault()方法。

下面是示例代码:

 
 
document.addEventListener('contextmenu', function(event) {
event.preventDefault(); // 阻止默认的右击菜单显示
});
提示:AI自动生成,仅供参考