Click here to Skip to main content
15,891,136 members
Articles / Web Development / ASP.NET
Alternative
Tip/Trick

Disable right click context menu cut, copy, paste

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
25 Nov 2011CPOL 9.3K   3
var message="Function Disabled!";function clickIE4(){if (event.button==2){alert(message);return false;}}function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){alert(message);return...
JavaScript
<script type="text/javascript">
var message="Function Disabled!";
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
</script>

This Will Work.I have tested In: Internet Explorer, Mozilla Firefox, Google Chrome.

No matter what you do, you can't prevent users from having full access to every bit of data on your website. Any Javascript you code can be rendered moot by simply turning off Javascript on the browser (or using a plugin like NoScript).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionnot working in google chrome Pin
ndsolanki.it20-Nov-12 0:06
ndsolanki.it20-Nov-12 0:06 
GeneralReason for my vote of 1 See my comments for the original ver... Pin
MadMyche25-Nov-11 9:15
professionalMadMyche25-Nov-11 9:15 
GeneralThis Code also Work...But When Disable Javascript it wont wo... Pin
Prince Antony G24-Nov-11 19:55
Prince Antony G24-Nov-11 19:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.