Disable Right Click on Website Using JavaScript

Disable Right Click on Website Using JavaScript

In this tutorial we will see how to Disable Right Click on Website Using JavaScript. .preventDefault() method and contextmenu event are used for this purpose.

HTML Code

HTML Code is given below.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Disable Right Click on Website Using JavaScript</title>
</head>
<body>
</body>
</html>

JavaScript Code

JavaScript Code is given below, In this code contextmenu event handler is attached with document, so that whenever right click event occurs the preventDefault() function is called which cancels the event and then message is displayed.

<script>
document.addEventListener("contextmenu", function(event){
event.preventDefault();
alert('Right Click is Disabled');
}, false);
</script>

Demo

Video Tutorial

Watch video tutorial on how to Disable Right Click on Website Using JavaScript.

Post a Comment

Previous Post Next Post