1

I have a phone gap/cordova application. I have a view that has a link, 2 textfields and text.

I want to remove copy,paste and select option from the web view.

Using:

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitUserSelect='none';"];

I was able to disable copy paste and select menu from web view, but it still lingers in the input fields , i.e textfields.

What i tried was to disable long press on the webview , that disable the magnify glass and as a result disables copy and paste menu, but the menu occurs while we double tap on the textfield too. How can i disable both long press and double taps on the webview?

I am bit confused whether my app will clear the review process for app store if i disable the magnify glass.

Please help me get a solution to this.

Kumar KL
  • 15,315
  • 9
  • 38
  • 60
user2903299
  • 101
  • 2
  • 9

3 Answers3

3

I think this has been discussed elsewhere but what ended up working for me was adding the following to the css.

/******************
disable select touch and hold and highlight colors
******************/
html {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color:rgba(0,0,0,0);
}

and if you still want it to work for input then I added

input {
    -webkit-user-select: auto !important;
    -webkit-touch-callout: default !important;
}

Thanks to Phonegap styles -webkit-user-select: none; disabling text field

Community
  • 1
  • 1
Leo
  • 1,495
  • 23
  • 41
  • thanks Leo...this works but not for any input area. This works only on links or texts. When i tap and hold on the input area , i still get the copy and paste menu. – user2903299 Oct 24 '13 at 05:46
  • hmmm I think I had the opposite problem and had to add it back in for inputs let me check – Leo Oct 25 '13 at 14:39
  • You are right I get the same behaviour. Sorry Thats all I got. Other than making your own textbox by using a text and listening for keystrokes. – Leo Oct 25 '13 at 14:49
0
 Use this.
 <style type="text/css">
 *:not(input):not(textarea) {
   -webkit-user-select: none; /* disable selection/Copy of UIWebView */
   -webkit-touch-callout: none; /* disable the IOS popup when long-press on a link */
  }       
 </style>
 If you want Disable only anchor button tag use this.

 a {-webkit-user-select: none; /* disable selection/Copy of UIWebView */
    -webkit-touch-callout: none; /* disable the IOS popup when long-press on a link */
 }
Narsingh Tomar
  • 487
  • 5
  • 15
0

I wonder why you want to remove copy & paste functionality: Security concerns? If you want keep text selection and copy & paste within your application BUT you want to prevent people to copy&paste your content to other apps then check out Cordova plugin cordova-disable-copy-paste

Marco Eidinger
  • 151
  • 2
  • 4
  • 1
    This might answer the question, but link-only answers are discouraged. Links tend to break; and then such answers turn (almost) useless. – GhostCat May 04 '17 at 13:20