aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

How to disable right click on web page using JavaScript | Disable mouse right click on webpage

Oct 30, 2011

Here I will explain how to disable right click on website using JavaScript.


One day I got requirement like do not allow users to right click on website to see source code of page for that I written JavaScript functionality to disable right click on website to achieve this create new website and design your Default.aspx page like this 

<html xmlns="">
<head runat="server">
<title>Sample to Disable Right Click of Page</title>
<script language="JavaScript" type="text/javascript">
//Message to display whenever right click on website
var message = "Sorry, Right Click have been disabled.";
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
return false;
else {
if (e.button == 2 || e.button == 3) {
return false;
if (document.all) {
document.onmousedown = click;
else {
document.onclick = click;
document.oncontextmenu = function () {
return false;

<form id="form1" runat="server">

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Dheeraj Bansal said...

Thanks Again !!!
This code really works as charm for me.

yaswanth kumar said...

hello! i need code to disable all the controls which able to copy the data in PDF file when opened in WEBSITE!!

PLZ.....MAKE it !!

Hazrat said...

Dear sir i m new to your website.Really very very usable and good.I like this site.

But sir i want know that one, whatever you have wrote for disabling right Click on a asp page, it works on IE only,
But i want to know what have to do for other Browser to disable rt clk.plz do the needfull.Thanks in adv.

besthavenki said...

thanking you very much

SaudiTamilan said...

This is useful script by suresh.One more thing is,write this script in .js file and save it in solution explorer 'script' folder and call it from Master page.

Anonymous said...

How to disable file upload & file download options using

Unknown said...

Thanks ...It is works

Anonymous said...

it's not working for me.... pls help

Suresh Burdak said...

Thanks Suresh!!!

Its working fine.....

Aayush Singh said...

Not working at all on chrome...

Anonymous said...

your site is very helpful.. Thanks a lot.
Sir i am trying to block save page as option in the menu of FF & IE web browser so the images, script do not get downloaded when user click save page as html format... I hv disable the right click menu, but still users can access the sources page from the main menu..

Kindly give your suggestion/advice on it, how can i do it

Suryakant Chouhan said...

Its working for IE not for Chrome...

Unknown said...


It is working only in IE.
Please show for all browsers.

God said...

Chutye... key bord se right click karega to view source hota hai..

Anonymous said...

Thank you Suresh, You provoide us many necessary things.
Use...(oncontextmenu="return false;") in body or any images or anywhere , where you don't want Right click.

Anonymous said...

it's not working

Anonymous said...


Suresh Dasari said...

Thanks for notifying me i made change now it's working fine check it..... Happy coding

Anonymous said...

It really helped me a lot..Thank u so much Suresh!!

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.