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.
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