user2903299
user2903299

Reputation: 101

Disable copy and paste from input fields in Webview in a phone gap/cordova based ios app.

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.

Upvotes: 1

Views: 2574

Answers (3)

Marco Eidinger
Marco Eidinger

Reputation: 151

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

Upvotes: 0

Narsingh Tomar
Narsingh Tomar

Reputation: 487

 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 */
 }

Upvotes: 0

Leo
Leo

Reputation: 1505

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

Upvotes: 3

Related Questions