Portal Home > Knowledgebase > How To's and more > How to Disable Right Click on Your Web Pages


How to Disable Right Click on Your Web Pages




To prevent someone from using the right mouse button on your site, paste the following code in your web page just above the body tag:

------------------------------------------------------------------------------

<SCRIPT language="JavaScript">
function click() {
if (event.button==2) {
alert('Copyright © 2003 YOURSITE.COM');
}

document.onmousedown=click
// -->
</SCRIPT> 
-----------------------------------------------------------------------------

Make sure you change YOURSITE.COM to what text you want shown.
OR

Our you could do it without loads of code. And you can write it yourself. Put this in your body tag: 
oncontextmenu="return false"

Example:
<body oncontextmenu="return false">

You can also disable select and drag like this:

<body oncontextmenu="return false" ondragstart="return false" onselectstart="return false">

====================================================
 

Here's a little bit more powerful script.

PHP:

--------------------------------------------------------------------------------
<script language=JavaScript>


var message="Function Disabled";
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(message);
return false;
}
}
else if (document.layers||document.getElementById) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->
</script>
 



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
File Extensions (Views: 1042)
cPanel Log-in Short Cut (Views: 1041)
.htaccess tips (Views: 1094)