8

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]

Roope Hakulinen
  • 7,326
  • 4
  • 43
  • 66
Humming Bird
  • 87
  • 1
  • 1
  • 6

2 Answers2

18

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

AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
  • when I use above code[for android 4.1 and 4.2], inputs placeholder disappears and user unable to enter any value in it. any other solution for android 4.1 and 4.2 – Humming Bird Dec 23 '14 at 10:37
  • You'll also want to add textarea to the second style declaration – Joe Withey Mar 31 '17 at 11:22
-1

Here is the solution I found and worked, but not through JS. Paste the following code in MainActivity.java file

super.appView.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                return true;
            }
});
N.K
  • 2,220
  • 1
  • 14
  • 44
Humming Bird
  • 87
  • 1
  • 1
  • 6