Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable text selection and copy paste in hybrid app using JS

I am trying to disable text selection and copy paste in phonegap applicaion by using following code.

CSS

-webkit-user-select:none;

JavaScript

$('body').on('cut copy paste',function(e){e.preventDefault();});

It works on all OS platforms including adroid 4.4+ but having issues on 4.1 and 4.2. Please Help.

Both doesn't support android 4.1.2 and 4.2.1.

[Tested on Micromax canvas 4 and samsung galaxy s2]

like image 274
Humming Bird Avatar asked Dec 23 '14 07:12

Humming Bird


People also ask

How do I restrict copy and paste in JavaScript?

You can use jquery for this: $('body'). bind('copy paste',function(e) { e. preventDefault(); return false; });

How do I turn off text selection?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I turn off copy and paste?

To disable the copy and paste function in PDFs, you need to prevent the ability to select text with the cursor. If a user can't select the text, then they can't right-click and copy with the mouse or use Ctrl-C as a keyboard command.


1 Answers

you can use css to do that

*
{
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

input
{
-webkit-user-select: auto !important;
-khtml-user-select: auto !important;
-moz-user-select: auto !important;
-ms-user-select: auto !important;
user-select: auto !important;
}

found here Disable Copy and Paste in Phonegap

like image 153
AtanuCSE Avatar answered Oct 05 '22 04:10

AtanuCSE