Disabling the Right-click Mouse Button
by Amrit HallanByteswoth.com
Tuesday, 9th August 2005
<script language=JavaScript>
var IE;
var NN;
if(navigator.appName=="Microsoft Internet Explorer")
{
IE=true;
}
if(navigator.appName=="Netscape")
{
NN=true;
}
The above code checks what browser the user is using and store the information accordingly. Both the browsers use different class variable names to store different events.
function right(click)
{
if(IE && (event.button==2 || event.button==3))
{
alert("The right click has been disabled here.");
return false;
}
if(NN && (click.which==2 || click.which==3))
{
alert("The right click has been disabled here.");
return false;
}
return false;
}
And the code below captures the event and sends it to the browser.
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
document.onmousedown=right;
document.onmouseup=right;
window.document.layers=right;
</script>
Options:
Printer Friendly
Email Friend
Amrit Hallan is a freelance web designer. For all web site development and web promotion needs, you can get in touch with him at amrit@bytesworth.com . For further details, visit http://www.bytesworth.com You can subscribe to his newsletter [BYTESWORTH REACHOUT] on Web Designing Tips & Tricks by sending a blank email at bytesworth-subscribe@topica.com.
