How To Disable Right Click on A Webpage?

By using oncontextmenu event and write return false; statement in its function’s body.

<!DOCTYPE html>
<html>
<head>
  <title>Right click is disabled</title>
</head>
<body>

  <h1 align="center">Right click is disabled on this webpage!!!</h1>

  <script>
  document.oncontextmenu=function()
  {
    alert("This action is prohibited on this webpage.");
    return false;
  }
  </script>
</body>
</html>

Or use attribute oncontextmenu attribute.

<!DOCTYPE html>
<html oncontextmenu="alert('This action can not be performed.');return false;">
<head>
  <title>Right click is disabled</title>
</head>
<body>

  <h1 align="center">Right click is disabled on this webpage!!!</h1>

</body>
</html>

Other Articles~

Leave a Comment