|
|
Stopping right clicks by visitorsIf you want to protect and secure content on your web page, you need to disable right clicking by visitors. When visitors right-click on a web page, they can copy images by selecting the appropriate option from the displayed menu. Here I'll show you how to prevent right clicks on a web page and thus (?... read note below) protecting and securing the images and content on your web page. We'll employ JavaScript and write a function that displays an "alert" box when the visitor right-clicks on the page. Try right-clicking on this page. Put the following code inside the HEAD of your HTML document. This will display an alert when a visitor right-clicks on the page. You can customize the text displayed in the alert box by changing the value of msg variable.
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function click(e)
{
var msg = "No right click is allowed";
if (document.all)
{
if (event.button == 2)
{
alert(msg);
return false;
}
}
if (document.layers)
{
if (e.which == 3)
{
alert(msg);
return false;
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
//-->
</script>
Note: This method is not foolproof. A visitor will still be able to save an image if he/she keeps the left mouse pressed and then right-clicks on the page. Also, this method will not work on older browsers or browsers in which JavaScript has been disabled.
Page contents: Stopping right clicks by visitor to prevent and protect images displayed on a web page.
Page URL: http://www.webdevelopersnotes.com/tips/html/ stopping_right_clicks_by_visitors.php3
|
|