.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Disable Right Click on the Page

Posted By:abhays       Posted Date: March 31, 2014    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

Disable Right Click on the Page using Javascript
 

We can disable right click on any page by below ways:-

1.    In this method we add a javascript method, in this we check the mouse click, if click is right click then a message is displayed like "Right click on the page disabled"is right click then a message is displayed like "Right click disabled"

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click on the page Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;	
   }
}
</script>

 

2.In this method, set the oncontextmenu="return false" in the body part

<html>
<head>
</head>
<Body>
  <Table>
   <tr oncontextmenu="return false">
    <td>
     Test
   </td>
  </tr>
 </Table>
</Body>
</html>


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend