Saturday, February 5, 2011

Restricting the user copying the Page Text



We can restrict users copying the text in our page by using a simple Jscript code.

<script language="JavaScript">
document.onselectstart=new Function ("return false");
</script>

One another way of restricting the users block copying the text is by disabling the right click on the webpage.
The following script is taken from a Microsoft KB article Q286426 and it only works with IE.

<script language="JavaScript">
var message = "Sorry, that function is disabled.\n\n";
message += "This page is copyrighted, and ";
message += "all content is protected.";
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = click;

No comments :

Post a Comment