17 November, 2005
Stopping Right-clicks with JavaScript
Of course, there isn't really any way to stop users from clicking on your pictures or viewing the source code of your frames, but this little bit of code makes it a good deal harder to right-click. Try right-clicking on this page. This trick only works with the latest browsers (4.x and higher). As the great Leonardo da Vinci once said, bad artists copy, good artists steal :-)
JavaScript Code
<script type="text/javascript">
<!--
function right(e) {
if (document.layers && e.which == 3) {
alert("Stop right-clicking!");
return false;
} else if (document.all && event.button == 2) {
alert("Stop right-clicking!");
return false;
}
return true;
}
document.onmousedown=right;
if (document.layers) {
window.captureEvents(Event.MOUSEDOWN);
}
//-->
</script>
Put this into your HTML document (preferably in the head section) and the right click is caught, preventing the user from easily saving your images to their hard disk, or viewing your source code.