Is it possible to disable text selection to make a PhoneGap app more similar to normal native app?
Something like this:
document.onselectstart = function() {return false;}
or:
* {
user-select: none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
}
Or many other things don't work.
Putting it on html
, not *
, works for me:
html {
-webkit-user-select: none;
}
I looked all over for help on this. This finally worked for me.
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
super.appView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
return true;
}
});
}
}
The setOnClickListener is what does the magic. Make sure you put this AFTER your call to super.loadUrl.
Of course, this will disable text selection for your entire app, but I'm OK with that, and I don't have any other way around it for now.
I'm not sure of the complete implications of this yet, but I do make use of the JqueryMobile event "taphold", and it still works fine. I believe this works by handling the long click on the appView (which hosts your HTML app) and preventing it from bubbling up.
this will work too.
<body oncontextmenu="return false" ondragstart="return false"
onselectstart="return false">
As well as what ThinkingStiff mentioned I also use the following to remove any highlighting/copy & paste
-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With