Home » Labs » Disable text selection and right click on website – trick with code  

Disable text selection and right click on website – trick with code


Filed under Labs

This post explains how to protect a webpage from copying pages contents including text and image. Its is not possible to protect 100% but we can make it harder to copy contents from a webpage. In order to block the right-click activity we need to use JavaScript which is one of the best scripting languages used to enhance webpage functionality. Below is the code take a look and use on your webpage.

To Disable Context Menu

<script>
	document.oncontextmenu = function(){return false;};
</script>

Paste above code on your webpage header section.

To Disable Text Selection

<script>
	document.onselectstart= function() {return false;};
</script>

This will disable Selection in IE and Chrome, to do the same in Mozilla Firefox we need to use CSS to the body element. Copy and paste below CSS to your master CSS file body section.

	-moz-user-select: none;
Tags:

Posts you may like: