Inspiration For Creative Minds
Home » Labs » 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

	document.oncontextmenu = function(){return false;};

Paste above code on your webpage header section.

To Disable Text Selection

	document.onselectstart= function() {return false;};

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;
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: