JS right click event

oncontextmenu event

When the user is

JavaScript is executed when the mouse is right-
clicked on the element : The oncontextmenu event is triggered when the user right-clicks the mouse in the element and opens the context menu.

<div id="demo"></div>
let demo = document.getElementById("demo");
 
demo.oncontextmenu = function(e) {
    
    
    e.preventDefault();
    // 执行代码块
    console.log(this)
}

e.preventDefault(); is to prevent the default event, you can start writing the code you want to execute later.
Or return false

Guess you like

Origin blog.csdn.net/weixin_46034375/article/details/108737885