In this tutorial we will learn how to Detect Right Click using JavaScript. For this we can use contextmenu event which fires when user tries to open context menu by using right click.
Table of Contents
JavaScript Code
Take a look at the JavaScript code given below.
<script>
document.addEventListener('contextmenu', (event) => {
alert("Right Click Detected!");
})
</script>
On each right click, contextmenu event is fired and the message is displayed with the help of alert box.
Video Tutorial
Watch video tutorial on this topic.