方法一
首先取消右键的系统默认弹窗
document.oncontextmenu = function(e){return false//或者 e.preventDefault()}
用onmouseup
或者onmousedown
代替点击事件
onclick事件无法用e.button判断鼠标左右键。
document.onmouseup = function(e){if(e.button == 2){console.log('右键点击了'); }}
(e.button == 0对应鼠标左键,e.button == 1对应鼠标中键)
方法二
浏览器默认行为 oncontextmenu事件
document.oncontextmenu = function(e){//点击右键后要执行的代码//.......return false;//阻止浏览器的默认弹窗行为}