Foren

How to disable copy and paste feature from my pages

Marcos Pereira, geändert vor 11 Jahren.

How to disable copy and paste feature from my pages

New Member Beitrag: 1 Beitrittsdatum: 31.10.12 Neueste Beiträge
Hello.

I would like to know if there is a possibility of disabling the copy and paste features from only some of my content?

Thank you.
thumbnail
André Bunse, geändert vor 11 Jahren.

RE: How to disable copy and paste feature from my pages

Junior Member Beiträge: 85 Beitrittsdatum: 16.03.12 Neueste Beiträge
You can disable copy and paste by binding "selectstart" and/or "mousedown" event on the underlying element of your content.
An easy way is using jQuery, than you can say:

jQuery("#myContent").bind("selectstart mousedown", function(event) {
  event.preventDefault();
});

the easiest way is using jQuery UI ;)

jQuery("#myContent").disableSelection();

to handle the events with pure javascript there is much more to do, especially if you want to be cross-browser compatible

HTH
André
thumbnail
Pavel Savinov, geändert vor 11 Jahren.

RE: How to disable copy and paste feature from my pages

Junior Member Beiträge: 94 Beitrittsdatum: 24.09.12 Neueste Beiträge
There is no need to prevent selection or mouse-down. JQuery allows to block particular events, like this:

jQuery(document).ready(function () {
	   jQuery("#DivToPreventCopyPaste").bind("copy paste", false);
   });
thumbnail
Prabhakar Singh, geändert vor 11 Jahren.

RE: How to disable copy and paste feature from my pages

New Member Beiträge: 8 Beitrittsdatum: 02.08.12 Neueste Beiträge
hey marcos ,

just try this line of code..it worked for me as i wanted to Disable copy and paste from one of my portlet page (which included a Registration Form)..!!

all you need to do is include these two lines of javascript code-

<script type="text/javascript">
document.oncopy=new Function("return false"); //Disable Copy using Javascript
document.onpaste = new Function("return false"); //Disable Paste using Javascript
</script>
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: How to disable copy and paste feature from my pages

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Users will still be able to download the source and just copy and paste the content in the local copy. :-)
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: How to disable copy and paste feature from my pages

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
Had a similar requirement.
I've converted text to images which I've uploaded to Documents and Media library with permission and I've also disabled context menu on view pages for regular users.